diff --git a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/Breaker.java b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/Breaker.java index ed25adbbb..6d382b4f1 100644 --- a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/Breaker.java +++ b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/Breaker.java @@ -280,7 +280,8 @@ static LineBreakResult doBreakCharacters( nextCharBreak = charIterator.next(); } - if (graphicsLength == avail) { + if (graphicsLength == avail && + graphicsLength > 0) { // Exact fit.. boolean needNewLine = currentString.length() > left; @@ -314,7 +315,8 @@ static LineBreakResult doBreakCharacters( graphicsLength += splitWidth; } - if (graphicsLength <= avail) { + if (graphicsLength <= avail && + graphicsLength > 0) { // The entire word fit. context.setWidth(graphicsLength); context.setEnd(nextCharBreak + context.getStart()); @@ -361,6 +363,7 @@ static LineBreakResult doBreakCharacters( // Empty string. context.setEnd(context.getStart()); context.setWidth(0); + context.setNeedsNewLine(false); return LineBreakResult.CHAR_BREAKING_FINISHED; } diff --git a/openhtmltopdf-examples/src/main/resources/visualtest/expected/issue-466-infinite-loop-table-cell-box.pdf b/openhtmltopdf-examples/src/main/resources/visualtest/expected/issue-466-infinite-loop-table-cell-box.pdf new file mode 100644 index 000000000..ac67ed56f Binary files /dev/null and b/openhtmltopdf-examples/src/main/resources/visualtest/expected/issue-466-infinite-loop-table-cell-box.pdf differ diff --git a/openhtmltopdf-examples/src/main/resources/visualtest/html/issue-466-infinite-loop-table-cell-box.html b/openhtmltopdf-examples/src/main/resources/visualtest/html/issue-466-infinite-loop-table-cell-box.html index 5ff10cdfd..b4c702cae 100644 --- a/openhtmltopdf-examples/src/main/resources/visualtest/html/issue-466-infinite-loop-table-cell-box.html +++ b/openhtmltopdf-examples/src/main/resources/visualtest/html/issue-466-infinite-loop-table-cell-box.html @@ -1,6 +1,31 @@ +
+ + +
GHI
+
DEF
+ + +
PQR STU
+
VWX 123
+ + +
+
+ + +
JKL
+
MNO
+ + +
+
+ +
ABC
+ +
diff --git a/openhtmltopdf-examples/src/test/java/com/openhtmltopdf/visualregressiontests/VisualRegressionTest.java b/openhtmltopdf-examples/src/test/java/com/openhtmltopdf/visualregressiontests/VisualRegressionTest.java index 6631e0e4c..e5f51d7ac 100644 --- a/openhtmltopdf-examples/src/test/java/com/openhtmltopdf/visualregressiontests/VisualRegressionTest.java +++ b/openhtmltopdf-examples/src/test/java/com/openhtmltopdf/visualregressiontests/VisualRegressionTest.java @@ -1019,9 +1019,12 @@ public void testIssue459RemUnitDefault() throws IOException { /** * Tests a reported infinite loop bug with table cells in specific * circumstances. + * + * Turns out this bug was triggered by zero width table cells + * with content and word-wrap: break-word. Therefore, this test + * also exercises zero width divs with content (and without). */ @Test - @Ignore // Infinite loop w memory allocation. public void testIssue466InfiniteLoopTableCellBox() throws IOException { assertTrue(vt.runTest("issue-466-infinite-loop-table-cell-box")); }