Skip to content

Can't use an equals sign "=" in a serverless.yml variable default #5136

Closed

Description

@jacobevans

This is a Bug Report

Description

When using ${var, default} syntax, if the default is a string with an "=" in it, the whole ${} construct will just be returned literally.

For example (this is in env variable section, for ease of demonstration) but it seems to apply anywhere)
serverless.yml:

provider: 
  environment:
    TEST1: ${self:does_not_exist, "This_is_fine"}
    TEST2: ${self:does_not_exist, "this=not_fine"}

shell:

$ sls package -s dev
$ cat .serverless/cloudformation-template-update-stack.json  | grep TEST
        "TEST1": "This_is_fine",
        "TEST2": "${self:does_not_exist, \"this=not_fine\"}",

I would expect TEST2 to have a value of this=not_fine

Additional Data

  • Serverless 1.28.0
  • Mac OSX

Activity

  1. ronkorving commented on Jul 24, 2018

    @ronkorving
    Contributor

    Interestingly, the regular expression used to detect constant strings, has a \1 reference in it, unlike all other regular expressions.

    I wonder if this has something to do with it. If not used properly, it can cause weird side-effects. For example:

    const stringRefSyntax = RegExp(/(?:('|").*?\1)/g);
    stringRefSyntax.exec('"this is fine"');
    // [""this is fine"", """, index: 0, input: ""this is fine"", groups: undefined]
    stringRefSyntax.exec('"this is fine"'); // same string! 2nd execution
    // null

    It may well be unrelated, but maybe it'll trigger an "aha" for someone :)

  2. mscharp commented on Nov 13, 2018

    @mscharp

    Has anyone taken a look at this? Anyway to get this fix prioritized?

  3. dschep commented on Nov 13, 2018

    @dschep
    Contributor

    Confirmed the bug in dschep-bug-repos/sls-5136, and even tried a few work arounds in hopes of a quick temporary fix, but to no avail 😢

    The regex using \1 makes sense AFAICT because you want a string starting with ' to end with ' and similarly for ".

  4. mscharp commented on Nov 13, 2018

    @mscharp

    I am no regex guru, but is the regex even the issue? Putting that regex into an online regex tester and "this=not_fine", shows that it matches the whole string... I would assume then that the regex isn't the problem?

    edited for spelling...

  5. dschep commented on Nov 13, 2018

    @dschep
    Contributor

    Agreed, @mscharp. Just addressing @ronkorving's thought about it.

  6. medikoo commented on Mar 3, 2021

    @medikoo
    Contributor

    Fixed with #8987

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions