Skip to content

Fix truncated environment variable expansions#662

Merged
srchase merged 1 commit intosmithy-lang:masterfrom
srchase:fix-truncated-env-expansions
Dec 8, 2020
Merged

Fix truncated environment variable expansions#662
srchase merged 1 commit intosmithy-lang:masterfrom
srchase:fix-truncated-env-expansions

Conversation

@srchase
Copy link
Copy Markdown
Contributor

@srchase srchase commented Dec 8, 2020

Any environment variable expansions in smithy-build.json that did not start at the beginning of the field resulted in dropping the character that preceded the ${NAME} placeholder.

Consider the following smithy-build.json example, with the environment variable of FOO was set to BAZ:

{
    "version": "1.0",
    "projections": {
        "a": {
            "transforms": [
                {
                    "name": "includeShapesByTag",
                    "args": {
                        "tags": ["BAR${FOO}"]
                    }
                }
            ]
        }
    }
}

Currently, this results in the shapes with the tag BABAZ being included, instead of BARBAZ as expected.

This CR corrects the expansion behavior to assure preceding characters are included appropriately.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@srchase srchase requested a review from mtdowling December 8, 2020 22:19
String replacement = expand(node.getSourceLocation(), variable);
// INLINE over-matches to allow for escaping. If the over-matched first group does not start with
// '${', we need to prepend the first character from that group on the replacement.
if (!matcher.group(0).startsWith("${")) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works, but it would probably be easier to understand if this used https://github.com/awslabs/smithy/blob/master/smithy-utils/src/main/java/software/amazon/smithy/utils/SimpleParser.java. I think we can merge this for now to fix the bug, and then go back and improve this when we have time.

@srchase srchase merged commit 5fcd31d into smithy-lang:master Dec 8, 2020
@srchase srchase deleted the fix-truncated-env-expansions branch December 8, 2020 23:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants