Skip to content

Commit

Permalink
Allow backslash-escaped terminators in content token string arguments…
Browse files Browse the repository at this point in the history
…; JENKINS-14132: Very long content string parameter triggers a StackOverflowError
  • Loading branch information
sarowe committed May 10, 2013
1 parent bdc4345 commit deb3200
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/main/java/org/jenkinsci/plugins/tokenmacro/Tokenizer.java
Expand Up @@ -47,9 +47,10 @@ class Tokenizer {
private static final String numberRegex = "-?[0-9]+(\\.[0-9]*)?";

private static final String boolRegex = "(true)|(false)";
// Sequence of (1) not \ " CR LF and (2) \ followed by non line terminator

private static final String stringRegex = "\"([^\\\\\"\\r\\n]|(\\\\.))*\"";
// Sequence of (1) not \ " CR LF and (2) \ followed by (CR)LF, or not CR LF
// Use possessive quantifier to prevent stack overflow (see JENKINS-14132)
private static final String stringRegex = "\"([^\\\\\"\\r\\n]|(\\\\(?:\r?\n|.)))*+\"";

private static final String valueRegex = "(" + numberRegex + ")|(" + boolRegex + ")|(" + stringRegex + ")";

Expand Down
Expand Up @@ -39,7 +39,32 @@ public void testNested() throws Exception {

assertEquals("{abc=[def, ghi], jkl=[true]}",TokenMacro.expand(b,listener,"${TEST_NESTED}"));
}


public void testVeryLongStringArg() throws Exception {
StringBuilder veryLongStringParam = new StringBuilder();
for (int i = 0 ; i < 500 ; ++i) {
veryLongStringParam.append("abc123 %_= ~");
}

FreeStyleProject p = createFreeStyleProject("foo");
FreeStyleBuild b = p.scheduleBuild2(0).get();

listener = new StreamTaskListener(System.out);

assertEquals("{arg=["+ veryLongStringParam + "]}",TokenMacro.expand(b,listener,"${TEST, arg=\"" + veryLongStringParam + "\"}"));
}

public void testMultilineStringArgs() throws Exception {
FreeStyleProject p = createFreeStyleProject("foo");
FreeStyleBuild b = p.scheduleBuild2(0).get();

listener = new StreamTaskListener(System.out);

assertEquals("{arg=[a \n b \r\n c]}\n",TokenMacro.expand(b, listener, "${TEST, arg = \"a \\\n b \\\r\n c\"}\n"));

assertEquals("${TEST, arg = \"a \n b \r\n c\"}\n",TokenMacro.expand(b, listener, "${TEST, arg = \"a \n b \r\n c\"}\n"));
}

public void testEscaped() throws Exception {
FreeStyleProject p = createFreeStyleProject("foo");
FreeStyleBuild b = p.scheduleBuild2(0).get();
Expand Down

0 comments on commit deb3200

Please sign in to comment.