Skip to content
Permalink
Browse files

Merge pull request #41 from sarowe/master

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 b0c21b81ddc3ed860e153a21f527eed508e7e1b8
@@ -140,7 +140,8 @@ public String transformText(String origText, ExtendedEmailPublisher publisher, E
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 + ")";

@@ -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");

0 comments on commit b0c21b8

Please sign in to comment.
You can’t perform that action at this time.