Skip to content
Permalink
Browse files
JENKINS-14132: Very long content token string parameter triggers a St…
…ackOverflowError
  • Loading branch information
Steve Rowe committed Jun 18, 2012
1 parent cd04b17 commit 14f50f8ce8f089c170002a345d5612e23ab24fae
Showing 2 changed files with 15 additions and 1 deletion.
@@ -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 + ")";

@@ -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 14f50f8

Please sign in to comment.