Skip to content

templates cannot have default values containing new lines #653

Open
@panzi

Description

@panzi

The default value of a variable cannot contain a new line (\n) character because .* doesn't match those. I.e. if you have this in your .env file:

FOO="${BAR:-multi
line}"

You get this error mesage:

2024/07/02 02:49:54 Invalid template: "${BAR:-multi\nline}"

This is a bit confusing, because this doesn't look like an invalid template. Because of the quotes the whole string is correctly parsed, the template has a valid name and does end with }. To fix this you need to change this regular expression:

var substitutionBraced = "[_a-z][_a-z0-9]*(?::?[-+?](.*))?"

To this:

var substitutionBraced = "[_a-z][_a-z0-9]*(?::?[-+?]((?:.|\n)*))?"

(I don't know if there is another way to match anything, including a \n, in Go.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions