Skip to content

Commit

Permalink
Optimize jsoup buffer test
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ars18wrw authored and dmitry.radchuk committed Apr 28, 2022
1 parent 8029098 commit 01507c5
Showing 1 changed file with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,23 @@ This file is part of the iText (R) project.

@Category(UnitTest.class)
public class ParserItTest extends ExtendedITextTest {
@Test

public void testIssue1251() {
// https://github.com/jhy/jsoup/issues/1251
StringBuilder str = new StringBuilder("<a href=\"\"ca");
for (int countSpaces = 0; countSpaces < 100000; countSpaces++) {
try {
Parser.htmlParser().setTrackErrors(1).parseInput(str.toString(), "");
} catch (Exception e) {
throw new AssertionError("failed at length " + str.length(), e);
}
str.insert(countSpaces, ' ');
String testString = "<a href=\"\"ca";

StringBuilder str = new StringBuilder();
// initial max length of the buffer is 2**15 * 0.75 = 24576
int spacesToReproduceIssue = 24577 - testString.length();
for (int i = 0; i < spacesToReproduceIssue; i++) {
str.append(" ");
}
str.append(testString);

try {
Parser.htmlParser().setTrackErrors(1).parseInput(str.toString(), "");
} catch (Exception e) {
throw new AssertionError("failed at length " + str.length(), e);
}
}

Expand Down

0 comments on commit 01507c5

Please sign in to comment.