Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #10 from sarowe/master
Address regressions in Email-ext v2.29 due to new dependency on token-macro-plugin: backslash-escaped terminators in content token string arguments no longer work; and very long content string parameters trigger StackOverflowErrors (JENKINS-14132)
  • Loading branch information
slide committed May 23, 2013
2 parents bdc4345 + deb3200 commit 806525f
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 806525f

Please sign in to comment.