Skip to content

Commit

Permalink
Merge pull request #41 from sarowe/master
Browse files Browse the repository at this point in the history
Fix for JENKINS-14132: Very long content token string parameter triggers a StackOverflowError
  • Loading branch information
slide committed Jun 18, 2012
2 parents cd04b17 + 14f50f8 commit b0c21b8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Expand Up @@ -140,7 +140,8 @@ static class Tokenizer {
private static final String boolRegex = "(true)|(false)";

// Sequence of (1) not \ " CR LF and (2) \ followed by (CR)LF, or not CR LF
private static final String stringRegex = "\"([^\\\\\"\\r\\n]|(\\\\(?:\r?\n|.)))*\"";
// 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 @@ -160,6 +160,19 @@ public void testTokenizer12() {
assertFalse(tokenizer.find());
}

public void testTokenizer_veryLongStringArg() {
ContentBuilder.Tokenizer tokenizer;
StringBuilder veryLongStringParam = new StringBuilder();
for (int i = 0 ; i < 500 ; ++i) {
veryLongStringParam.append("abc123 %_= ~");
}
tokenizer = new ContentBuilder.Tokenizer("${TEST, arg = \"" + veryLongStringParam.toString() + "\"}");
assertTrue(tokenizer.find());
assertEquals("TEST", tokenizer.getTokenName());
assertEquals(1, tokenizer.getArgs().size());
assertNotNull(tokenizer.getArgs().get("arg"));
}

public void testMultilineStringArgs() {
ContentBuilder.Tokenizer tokenizer;
tokenizer = new ContentBuilder.Tokenizer( "${TEST, arg = \"a \\\n b \\\r\n c\"}\n");
Expand Down

0 comments on commit b0c21b8

Please sign in to comment.