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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.

replacement = matcher.group(0).charAt(0) + replacement;
}
matcher.appendReplacement(builder, replacement);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public void addsBuiltinPlugins() {
@Test
public void expandsEnvironmentVariables() {
System.setProperty("FOO", "Hi");
System.setProperty("BAR", "TagFromEnv");
System.setProperty("NAME_KEY", "name");
SmithyBuildConfig config = SmithyBuildConfig.load(
Paths.get(getResourcePath("config-with-env.json")));
Expand All @@ -129,7 +130,7 @@ public void expandsEnvironmentVariables() {
assertThat(transform.getName(), equalTo("includeShapesByTag"));
// Did the array and string values in it expand?
assertThat(transform.getArgs(), equalTo(Node.objectNode()
.withMember("tags", Node.fromStrings("Hi", "${BAZ}"))));
.withMember("tags", Node.fromStrings("Hi", "compoundTagFromEnv", "${BAZ}"))));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"args": {
"tags": [
"${FOO}",
"compound${BAR}",
"\\${BAZ}"
]
}
Expand Down