Skip to content

Commit 01507c5

Browse files
ars18wrwdmitry.radchuk
authored andcommitted
Optimize jsoup buffer test
There is no need in checking the issue for strings of length equal to 12, 13, ..., n We can check it for a string of length m, where m - is the length for which the issue can be reproduced. The change has been introduced in a view of a test failing on Android (30+ versions) DEVSIX-6565
1 parent 8029098 commit 01507c5

File tree

1 file changed

+15
-9
lines changed
  • styled-xml-parser/src/test/java/com/itextpdf/styledxmlparser/jsoup/parser

1 file changed

+15
-9
lines changed

styled-xml-parser/src/test/java/com/itextpdf/styledxmlparser/jsoup/parser/ParserItTest.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,23 @@ This file is part of the iText (R) project.
3535

3636
@Category(UnitTest.class)
3737
public class ParserItTest extends ExtendedITextTest {
38-
@Test
38+
3939
public void testIssue1251() {
4040
// https://github.com/jhy/jsoup/issues/1251
41-
StringBuilder str = new StringBuilder("<a href=\"\"ca");
42-
for (int countSpaces = 0; countSpaces < 100000; countSpaces++) {
43-
try {
44-
Parser.htmlParser().setTrackErrors(1).parseInput(str.toString(), "");
45-
} catch (Exception e) {
46-
throw new AssertionError("failed at length " + str.length(), e);
47-
}
48-
str.insert(countSpaces, ' ');
41+
String testString = "<a href=\"\"ca";
42+
43+
StringBuilder str = new StringBuilder();
44+
// initial max length of the buffer is 2**15 * 0.75 = 24576
45+
int spacesToReproduceIssue = 24577 - testString.length();
46+
for (int i = 0; i < spacesToReproduceIssue; i++) {
47+
str.append(" ");
48+
}
49+
str.append(testString);
50+
51+
try {
52+
Parser.htmlParser().setTrackErrors(1).parseInput(str.toString(), "");
53+
} catch (Exception e) {
54+
throw new AssertionError("failed at length " + str.length(), e);
4955
}
5056
}
5157

0 commit comments

Comments
 (0)