Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix truncated environment variable expansions #662

Merged
merged 1 commit into from
Dec 8, 2020

Conversation

srchase
Copy link
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.

@@ -115,6 +115,11 @@ public Node stringNode(StringNode node) {
while (matcher.find()) {
String variable = matcher.group(1);
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
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