Skip to content

Commit

Permalink
Trim function params in TemplateExpander
Browse files Browse the repository at this point in the history
There is a MacOS integration test that checks that we're trimming before
looking up labels, but it only checks for genrules, which aren't using this
code path yet.

This was changed in 1a8d6b8 and we could see breakages in non-genrule
usage if a release picks up that change but not this.

PiperOrigin-RevId: 173393718
  • Loading branch information
ulfjack authored and dslomov committed Oct 25, 2017
1 parent 60fc02b commit 1961736
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ private String expand(TemplateContext context, int depth) throws ExpansionExcept
result.append(value);
} else {
String name = var.substring(0, spaceIndex);
String param = var.substring(spaceIndex + 1);
// Trim the string to remove leading and trailing whitespace.
String param = var.substring(spaceIndex + 1).trim();
String value = context.lookupFunction(name, param);
result.append(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,11 @@ public void testDollarDollar() throws Exception {
assertThat(expand("$${file%:.*8}")).isEqualTo("${file%:.*8}");
assertThat(expand("$$(basename file)")).isEqualTo("$(basename file)");
}

// Regression test: check that the parameter is trimmed before expanding.
@Test
public void testFunctionExpansionIsTrimmed() throws Exception {
context.functions.put("foo", (String p) -> "FOO(" + p + ")");
assertThat(expand("$(foo baz )")).isEqualTo("FOO(baz)");
}
}

0 comments on commit 1961736

Please sign in to comment.