- Revision
- 285016
- Author
- commit-qu...@webkit.org
- Date
- 2021-10-28 19:53:47 -0700 (Thu, 28 Oct 2021)
Log Message
Source/WebCore:
Negative length returned by TextUtil::midWordBreak with surrogate pair
https://bugs.webkit.org/show_bug.cgi?id=232053
Patch by Gabriel Nava Marino <gnavamar...@apple.com> on 2021-10-28
Reviewed by Alan Bujtas.
When the substring does not fit, the right side is supposed to be the start
of the surrogate pair if applicable. However, if the start of the surrogate
pair falls to the left of the startPosition, we will end up returning a
negative length. Instead, bail out at this point since we know that our
middle point (which becomes the right) falls before the start position.
We are not going to find a non-empty fitting content anymore in here.
* layout/formattingContexts/inline/text/TextUtil.cpp:
(WebCore::Layout::TextUtil::breakWord):
LayoutTests:
Add an additional edge case for surrogate pairs to existing tests.
https://bugs.webkit.org/show_bug.cgi?id=232053
Patch by Gabriel Nava Marino <gnavamar...@apple.com> on 2021-10-28
Reviewed by Alan Bujtas.
* fast/text/word-break-column-gap-display-flex-utf16-surrogates-expected.txt:
* fast/text/word-break-column-gap-display-flex-utf16-surrogates.html:
* fast/text/word-break-letter-spacing-utf16-surrogates-expected.txt:
* fast/text/word-break-letter-spacing-utf16-surrogates.html:
* fast/text/word-break-max-width-utf16-surrogates-expected.txt:
* fast/text/word-break-max-width-utf16-surrogates.html:
Modified Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (285015 => 285016)
--- trunk/LayoutTests/ChangeLog 2021-10-29 02:19:51 UTC (rev 285015)
+++ trunk/LayoutTests/ChangeLog 2021-10-29 02:53:47 UTC (rev 285016)
@@ -1,3 +1,17 @@
+2021-10-28 Gabriel Nava Marino <gnavamar...@apple.com>
+
+ Add an additional edge case for surrogate pairs to existing tests.
+ https://bugs.webkit.org/show_bug.cgi?id=232053
+
+ Reviewed by Alan Bujtas.
+
+ * fast/text/word-break-column-gap-display-flex-utf16-surrogates-expected.txt:
+ * fast/text/word-break-column-gap-display-flex-utf16-surrogates.html:
+ * fast/text/word-break-letter-spacing-utf16-surrogates-expected.txt:
+ * fast/text/word-break-letter-spacing-utf16-surrogates.html:
+ * fast/text/word-break-max-width-utf16-surrogates-expected.txt:
+ * fast/text/word-break-max-width-utf16-surrogates.html:
+
2021-10-28 Nikos Mouchtaris <nmouchta...@apple.com>
if border-radius includes a var(), the value is not readable from .style
Modified: trunk/LayoutTests/fast/text/word-break-column-gap-display-flex-utf16-surrogates-expected.txt (285015 => 285016)
--- trunk/LayoutTests/fast/text/word-break-column-gap-display-flex-utf16-surrogates-expected.txt 2021-10-29 02:19:51 UTC (rev 285015)
+++ trunk/LayoutTests/fast/text/word-break-column-gap-display-flex-utf16-surrogates-expected.txt 2021-10-29 02:53:47 UTC (rev 285016)
@@ -12,4 +12,6 @@
�r�
�𐀀
𐀀�
+r��r
+r𐀀r
PASS
Modified: trunk/LayoutTests/fast/text/word-break-column-gap-display-flex-utf16-surrogates.html (285015 => 285016)
--- trunk/LayoutTests/fast/text/word-break-column-gap-display-flex-utf16-surrogates.html 2021-10-29 02:19:51 UTC (rev 285015)
+++ trunk/LayoutTests/fast/text/word-break-column-gap-display-flex-utf16-surrogates.html 2021-10-29 02:53:47 UTC (rev 285016)
@@ -48,6 +48,12 @@
// surrogate lead + surrogate trail + surrogate lead
document.getElementById("div14").append("\ud800\udc00\ud800");
+
+ // single + surrogate trail + surrogate lead + single
+ document.getElementById("div15").append("r\udc00\ud800r");
+
+ // single + surrogate lead + surrogate trail + single
+ document.getElementById("div16").append("r\ud800\udc00r");
if (window.testRunner)
testRunner.dumpAsText();
@@ -67,4 +73,6 @@
<div id="div12"></div>
<div id="div13"></div>
<div id="div14"></div>
+<div id="div15"></div>
+<div id="div16"></div>
PASS
Modified: trunk/LayoutTests/fast/text/word-break-letter-spacing-utf16-surrogates-expected.txt (285015 => 285016)
--- trunk/LayoutTests/fast/text/word-break-letter-spacing-utf16-surrogates-expected.txt 2021-10-29 02:19:51 UTC (rev 285015)
+++ trunk/LayoutTests/fast/text/word-break-letter-spacing-utf16-surrogates-expected.txt 2021-10-29 02:53:47 UTC (rev 285016)
@@ -12,4 +12,6 @@
�r�
�𐀀
𐀀�
+r��r
+r𐀀r
PASS
Modified: trunk/LayoutTests/fast/text/word-break-letter-spacing-utf16-surrogates.html (285015 => 285016)
--- trunk/LayoutTests/fast/text/word-break-letter-spacing-utf16-surrogates.html 2021-10-29 02:19:51 UTC (rev 285015)
+++ trunk/LayoutTests/fast/text/word-break-letter-spacing-utf16-surrogates.html 2021-10-29 02:53:47 UTC (rev 285016)
@@ -48,6 +48,12 @@
// surrogate lead + surrogate trail + surrogate lead
document.getElementById("div14").append("\ud800\udc00\ud800");
+ // single + surrogate trail + surrogate lead + single
+ document.getElementById("div15").append("r\udc00\ud800r");
+
+ // single + surrogate lead + surrogate trail + single
+ document.getElementById("div16").append("r\ud800\udc00r");
+
if (window.testRunner)
testRunner.dumpAsText();
};
@@ -66,4 +72,6 @@
<div id="div12"></div>
<div id="div13"></div>
<div id="div14"></div>
+<div id="div15"></div>
+<div id="div16"></div>
PASS
Modified: trunk/LayoutTests/fast/text/word-break-max-width-utf16-surrogates-expected.txt (285015 => 285016)
--- trunk/LayoutTests/fast/text/word-break-max-width-utf16-surrogates-expected.txt 2021-10-29 02:19:51 UTC (rev 285015)
+++ trunk/LayoutTests/fast/text/word-break-max-width-utf16-surrogates-expected.txt 2021-10-29 02:53:47 UTC (rev 285016)
@@ -12,4 +12,6 @@
�r�
�𐀀
𐀀�
+r��r
+r𐀀r
PASS
Modified: trunk/LayoutTests/fast/text/word-break-max-width-utf16-surrogates.html (285015 => 285016)
--- trunk/LayoutTests/fast/text/word-break-max-width-utf16-surrogates.html 2021-10-29 02:19:51 UTC (rev 285015)
+++ trunk/LayoutTests/fast/text/word-break-max-width-utf16-surrogates.html 2021-10-29 02:53:47 UTC (rev 285016)
@@ -48,6 +48,12 @@
// surrogate lead + surrogate trail + surrogate lead
document.getElementById("div14").append("\ud800\udc00\ud800");
+ // single + surrogate trail + surrogate lead + single
+ document.getElementById("div15").append("r\udc00\ud800r");
+
+ // single + surrogate lead + surrogate trail + single
+ document.getElementById("div16").append("r\ud800\udc00r");
+
if (window.testRunner)
testRunner.dumpAsText();
};
@@ -66,4 +72,6 @@
<div id="div12"></div>
<div id="div13"></div>
<div id="div14"></div>
+<div id="div15"></div>
+<div id="div16"></div>
PASS
Modified: trunk/Source/WebCore/ChangeLog (285015 => 285016)
--- trunk/Source/WebCore/ChangeLog 2021-10-29 02:19:51 UTC (rev 285015)
+++ trunk/Source/WebCore/ChangeLog 2021-10-29 02:53:47 UTC (rev 285016)
@@ -1,3 +1,20 @@
+2021-10-28 Gabriel Nava Marino <gnavamar...@apple.com>
+
+ Negative length returned by TextUtil::midWordBreak with surrogate pair
+ https://bugs.webkit.org/show_bug.cgi?id=232053
+
+ Reviewed by Alan Bujtas.
+
+ When the substring does not fit, the right side is supposed to be the start
+ of the surrogate pair if applicable. However, if the start of the surrogate
+ pair falls to the left of the startPosition, we will end up returning a
+ negative length. Instead, bail out at this point since we know that our
+ middle point (which becomes the right) falls before the start position.
+ We are not going to find a non-empty fitting content anymore in here.
+
+ * layout/formattingContexts/inline/text/TextUtil.cpp:
+ (WebCore::Layout::TextUtil::breakWord):
+
2021-10-28 Nikos Mouchtaris <nmouchta...@apple.com>
if border-radius includes a var(), the value is not readable from .style
Modified: trunk/Source/WebCore/layout/formattingContexts/inline/text/TextUtil.cpp (285015 => 285016)
--- trunk/Source/WebCore/layout/formattingContexts/inline/text/TextUtil.cpp 2021-10-29 02:19:51 UTC (rev 285015)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/text/TextUtil.cpp 2021-10-29 02:53:47 UTC (rev 285016)
@@ -151,6 +151,8 @@
// We should never break in the middle of a surrogate pair. They are considered one joint entity.
auto offset = index + 1;
U16_SET_CP_LIMIT(text, 0, offset, text.length());
+
+ // Returns the index at trail.
return offset - 1;
};
@@ -169,9 +171,11 @@
left = middle + 1;
leftSideWidth = width;
} else if (width > availableWidth) {
- // When the substring does not fit, the right side is supposed to be the start of the surrogate pair if applicable.
+ // When the substring does not fit, the right side is supposed to be the start of the surrogate pair if applicable, unless startPosition falls between surrogate pair.
right = middle;
U16_SET_CP_START(text, 0, right);
+ if (right < startPosition)
+ return { };
} else {
right = middle + 1;
leftSideWidth = width;