Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace CR/NL by space - don't remove altogether when xml:space=default #32888

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Ahmad-S792
Copy link
Contributor

@Ahmad-S792 Ahmad-S792 commented Aug 29, 2024

2fbcfd8

Replace CR/NL by space - don't remove altogether when xml:space=default
https://bugs.webkit.org/show_bug.cgi?id=278524
rdar://134545958

Reviewed by NOBODY (OOPS!).

This patch aligns WebKit with Gecko / Firefox and Blink / Chromium.

Merge: https://chromium.googlesource.com/chromium/src.git/+/0c39a6f29e59594a7b9c412a8203af9fc43e4ecd

This moves handling of xml:space=default closer to the more generic
white-space handling, by not removing CR and NL characters, but rather
just replacing them with a regular space.

* Source/WebCore/rendering/svg/RenderSVGInlineText.cpp:
(WebCore::normalizeWhitespace): Renamed from `applySVGWhitespaceRules`
(WebCore::RenderSVGInlineText::RenderSVGInlineText):
(WebCore::RenderSVGInlineText::styleDidChange):
* LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Element-childElementCount-dynamic-add-svg-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Element-childElementCount-dynamic-remove-svg-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Element-childElementCount-svg-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Element-firstElementChild-svg-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Element-previousElementSibling-svg-expected.txt:
* LayoutTests/platform/glib/svg/custom/text-whitespace-handling-expected.txt:
* LayoutTests/platform/glib/svg/text/font-size-below-point-five-expected.txt:
* LayoutTests/platform/glib/svg/text/text-tselect-02-f-expected.txt:
* LayoutTests/platform/glib/svg/text/text-ws-01-t-expected.txt:
* LayoutTests/platform/glib/svg/text/textPathBoundsBug-expected.txt:
* LayoutTests/platform/ios/imported/w3c/web-platform-tests/svg/import/text-altglyph-01-b-manual-expected.txt:
* LayoutTests/platform/ios/imported/w3c/web-platform-tests/svg/import/text-tselect-02-f-manual-expected.txt:
* LayoutTests/platform/ios/imported/w3c/web-platform-tests/svg/import/text-tselect-03-f-manual-expected.txt:
* LayoutTests/platform/ios/svg/W3C-SVG-1.1/styling-css-02-b-expected.txt:
* LayoutTests/platform/ios/svg/W3C-SVG-1.1/text-align-08-b-expected.txt:
* LayoutTests/platform/ios/svg/text/text-altglyph-01-b-expected.txt:
* LayoutTests/platform/ios/svg/text/text-ws-01-t-expected.txt:
* LayoutTests/platform/mac/imported/w3c/web-platform-tests/svg/import/text-altglyph-01-b-manual-expected.txt:
* LayoutTests/platform/mac/imported/w3c/web-platform-tests/svg/import/text-tselect-02-f-manual-expected.txt:
* LayoutTests/platform/mac/imported/w3c/web-platform-tests/svg/import/text-tselect-03-f-manual-expected.txt:
* LayoutTests/platform/mac/svg/W3C-SVG-1.1/styling-css-02-b-expected.txt:
* LayoutTests/platform/mac/svg/W3C-SVG-1.1/text-align-08-b-expected.txt:
* LayoutTests/platform/mac/svg/W3C-SVG-1.1/text-tselect-02-f-expected.txt:
* LayoutTests/platform/mac/svg/W3C-SVG-1.1/text-ws-01-t-expected.txt:
* LayoutTests/platform/mac/svg/custom/text-whitespace-handling-expected.txt:
* LayoutTests/platform/mac/svg/text/font-size-below-point-five-expected.txt:
* LayoutTests/platform/mac/svg/text/text-tselect-02-f-expected.txt:
* LayoutTests/platform/mac/svg/text/text-ws-01-t-expected.txt:
* LayoutTests/platform/mac/svg/zoom/page/zoom-mask-with-percentages-expected.txt:
* LayoutTests/platform/wpe/svg/W3C-SVG-1.1/styling-css-02-b-expected.txt:
* LayoutTests/platform/wpe/svg/W3C-SVG-1.1/text-align-08-b-expected.txt:
* LayoutTests/platform/wpe/svg/W3C-SVG-1.1/text-altglyph-01-b-expected.txt:
* LayoutTests/platform/wpe/svg/W3C-SVG-1.1/text-tselect-02-f-expected.txt:
* LayoutTests/platform/wpe/svg/W3C-SVG-1.1/text-ws-01-t-expected.txt:
* LayoutTests/platform/wpe/svg/text/text-altglyph-01-b-expected.txt:
* LayoutTests/svg/custom/invalid-text-content-expected.txt:
* LayoutTests/svg/dom/altGlyph-dom-expected.txt:
* LayoutTests/platform/glib/imported/w3c/web-platform-tests/svg/import/paths-dom-01-f-manual-expected.txt:
* LayoutTests/platform/glib/imported/w3c/web-platform-tests/svg/import/styling-css-02-b-manual-expected.txt:
* LayoutTests/platform/glib/imported/w3c/web-platform-tests/svg/import/text-align-04-b-manual-expected.txt:
* LayoutTests/platform/glib/imported/w3c/web-platform-tests/svg/import/text-align-06-b-manual-expected.txt:
* LayoutTests/platform/glib/imported/w3c/web-platform-tests/svg/import/text-align-08-b-manual-expected.txt:
* LayoutTests/platform/glib/imported/w3c/web-platform-tests/svg/import/text-altglyph-01-b-manual-expected.txt:
* LayoutTests/platform/glib/imported/w3c/web-platform-tests/svg/import/text-dom-01-f-manual-expected.txt:
* LayoutTests/platform/glib/imported/w3c/web-platform-tests/svg/import/text-tselect-02-f-manual-expected.txt:
* LayoutTests/platform/glib/imported/w3c/web-platform-tests/svg/import/text-tselect-03-f-manual-expected.txt:
* LayoutTests/platform/gtk/svg/W3C-SVG-1.1/text-align-08-b-expected.txt:
* LayoutTests/platform/gtk/svg/W3C-SVG-1.1/text-tselect-02-f-expected.txt:
* LayoutTests/platform/gtk/svg/W3C-SVG-1.1/text-ws-01-t-expected.txt:
* LayoutTests/platform/ios/svg/W3C-SVG-1.1/text-altglyph-01-b-expected.txt:
* LayoutTests/platform/ios/svg/W3C-SVG-1.1/text-tselect-02-f-expected.txt:
* LayoutTests/platform/ios/svg/custom/text-whitespace-handling-expected.txt:
* LayoutTests/platform/ios/svg/text/font-size-below-point-five-expected.txt:
* LayoutTests/platform/ios/svg/text/text-align-01-b-expected.txt:
* LayoutTests/platform/ios/svg/text/text-hkern-expected.txt:
* LayoutTests/platform/ios/svg/text/text-tselect-02-f-expected.txt:
* LayoutTests/platform/ios/svg/text/text-ws-01-t-expected.txt:
* LayoutTests/platform/mac-sonoma/svg/W3C-SVG-1.1/text-tselect-02-f-expected.txt:
* LayoutTests/platform/wpe/svg/W3C-SVG-1.1/interact-order-01-b-expected.txt:
* LayoutTests/svg/text/textPathBoundsBug-expected.txt:
* LayoutTests/platform/ios/svg/text/text-align-01-b-expected.txt:
* LayoutTests/platform/ios/svg/text/text-altglyph-01-b-expected.txt:
* LayoutTests/platform/ios/svg/text/text-ws-01-t-expected.txt:
* LayoutTests/platform/ios/svg/W3C-SVG-1.1/text-ws-01-t-expected.txt:
* LayoutTests/svg/W3C-SVG-1.1/styling-css-02-b-expected.txt:

2fbcfd8

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 wincairo
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2 ✅ 🧪 wincairo-tests
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe
✅ 🧪 ios-wk2-wpt ✅ 🧪 mac-wk1 ✅ 🛠 wpe-cairo
✅ 🧪 api-ios ✅ 🧪 mac-wk2 ✅ 🛠 gtk
✅ 🛠 vision ✅ 🧪 mac-AS-debug-wk2 ✅ 🧪 gtk-wk2
✅ 🛠 vision-sim ✅ 🧪 mac-wk2-stress ❌ 🧪 api-gtk
✅ 🧪 vision-wk2 ✅ 🧪 mac-intel-wk2
✅ 🛠 tv
✅ 🛠 tv-sim
✅ 🛠 watch
✅ 🛠 watch-sim

@Ahmad-S792 Ahmad-S792 self-assigned this Aug 29, 2024
@Ahmad-S792 Ahmad-S792 added the SVG For bugs in the SVG implementation. label Aug 29, 2024
@Ahmad-S792 Ahmad-S792 changed the title Replace CR/NL by space - don't remove altogether when xml:space=default https://bugs.webkit.org/show_bug.cgi?id=278524 rdar://134545958 Replace CR/NL by space - don't remove altogether when xml:space=default Aug 29, 2024
@Ahmad-S792 Ahmad-S792 force-pushed the eng/Replace-CRNL-by-space---dont-remove-altogether-when-xmlspacedefault branch from 86898fe to 9b4ab67 Compare August 29, 2024 14:04
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Aug 29, 2024
@Ahmad-S792 Ahmad-S792 removed the merging-blocked Applied to prevent a change from being merged label Aug 29, 2024
@Ahmad-S792 Ahmad-S792 force-pushed the eng/Replace-CRNL-by-space---dont-remove-altogether-when-xmlspacedefault branch from 9b4ab67 to ddddc32 Compare August 29, 2024 18:29
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Aug 29, 2024
@Ahmad-S792 Ahmad-S792 removed the merging-blocked Applied to prevent a change from being merged label Aug 30, 2024
@Ahmad-S792 Ahmad-S792 force-pushed the eng/Replace-CRNL-by-space---dont-remove-altogether-when-xmlspacedefault branch from ddddc32 to c7fb8b6 Compare August 30, 2024 12:03
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Aug 30, 2024
https://bugs.webkit.org/show_bug.cgi?id=278524
rdar://134545958

Reviewed by NOBODY (OOPS!).

This patch aligns WebKit with Gecko / Firefox and Blink / Chromium.

Merge: https://chromium.googlesource.com/chromium/src.git/+/0c39a6f29e59594a7b9c412a8203af9fc43e4ecd

This moves handling of xml:space=default closer to the more generic
white-space handling, by not removing CR and NL characters, but rather
just replacing them with a regular space.

* Source/WebCore/rendering/svg/RenderSVGInlineText.cpp:
(WebCore::normalizeWhitespace): Renamed from `applySVGWhitespaceRules`
(WebCore::RenderSVGInlineText::RenderSVGInlineText):
(WebCore::RenderSVGInlineText::styleDidChange):
* LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Element-childElementCount-dynamic-add-svg-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Element-childElementCount-dynamic-remove-svg-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Element-childElementCount-svg-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Element-firstElementChild-svg-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Element-previousElementSibling-svg-expected.txt:
* LayoutTests/platform/glib/svg/custom/text-whitespace-handling-expected.txt:
* LayoutTests/platform/glib/svg/text/font-size-below-point-five-expected.txt:
* LayoutTests/platform/glib/svg/text/text-tselect-02-f-expected.txt:
* LayoutTests/platform/glib/svg/text/text-ws-01-t-expected.txt:
* LayoutTests/platform/glib/svg/text/textPathBoundsBug-expected.txt:
* LayoutTests/platform/ios/imported/w3c/web-platform-tests/svg/import/text-altglyph-01-b-manual-expected.txt:
* LayoutTests/platform/ios/imported/w3c/web-platform-tests/svg/import/text-tselect-02-f-manual-expected.txt:
* LayoutTests/platform/ios/imported/w3c/web-platform-tests/svg/import/text-tselect-03-f-manual-expected.txt:
* LayoutTests/platform/ios/svg/W3C-SVG-1.1/styling-css-02-b-expected.txt:
* LayoutTests/platform/ios/svg/W3C-SVG-1.1/text-align-08-b-expected.txt:
* LayoutTests/platform/ios/svg/text/text-altglyph-01-b-expected.txt:
* LayoutTests/platform/ios/svg/text/text-ws-01-t-expected.txt:
* LayoutTests/platform/mac/imported/w3c/web-platform-tests/svg/import/text-altglyph-01-b-manual-expected.txt:
* LayoutTests/platform/mac/imported/w3c/web-platform-tests/svg/import/text-tselect-02-f-manual-expected.txt:
* LayoutTests/platform/mac/imported/w3c/web-platform-tests/svg/import/text-tselect-03-f-manual-expected.txt:
* LayoutTests/platform/mac/svg/W3C-SVG-1.1/styling-css-02-b-expected.txt:
* LayoutTests/platform/mac/svg/W3C-SVG-1.1/text-align-08-b-expected.txt:
* LayoutTests/platform/mac/svg/W3C-SVG-1.1/text-tselect-02-f-expected.txt:
* LayoutTests/platform/mac/svg/W3C-SVG-1.1/text-ws-01-t-expected.txt:
* LayoutTests/platform/mac/svg/custom/text-whitespace-handling-expected.txt:
* LayoutTests/platform/mac/svg/text/font-size-below-point-five-expected.txt:
* LayoutTests/platform/mac/svg/text/text-tselect-02-f-expected.txt:
* LayoutTests/platform/mac/svg/text/text-ws-01-t-expected.txt:
* LayoutTests/platform/mac/svg/zoom/page/zoom-mask-with-percentages-expected.txt:
* LayoutTests/platform/wpe/svg/W3C-SVG-1.1/styling-css-02-b-expected.txt:
* LayoutTests/platform/wpe/svg/W3C-SVG-1.1/text-align-08-b-expected.txt:
* LayoutTests/platform/wpe/svg/W3C-SVG-1.1/text-altglyph-01-b-expected.txt:
* LayoutTests/platform/wpe/svg/W3C-SVG-1.1/text-tselect-02-f-expected.txt:
* LayoutTests/platform/wpe/svg/W3C-SVG-1.1/text-ws-01-t-expected.txt:
* LayoutTests/platform/wpe/svg/text/text-altglyph-01-b-expected.txt:
* LayoutTests/svg/custom/invalid-text-content-expected.txt:
* LayoutTests/svg/dom/altGlyph-dom-expected.txt:
* LayoutTests/platform/glib/imported/w3c/web-platform-tests/svg/import/paths-dom-01-f-manual-expected.txt:
* LayoutTests/platform/glib/imported/w3c/web-platform-tests/svg/import/styling-css-02-b-manual-expected.txt:
* LayoutTests/platform/glib/imported/w3c/web-platform-tests/svg/import/text-align-04-b-manual-expected.txt:
* LayoutTests/platform/glib/imported/w3c/web-platform-tests/svg/import/text-align-06-b-manual-expected.txt:
* LayoutTests/platform/glib/imported/w3c/web-platform-tests/svg/import/text-align-08-b-manual-expected.txt:
* LayoutTests/platform/glib/imported/w3c/web-platform-tests/svg/import/text-altglyph-01-b-manual-expected.txt:
* LayoutTests/platform/glib/imported/w3c/web-platform-tests/svg/import/text-dom-01-f-manual-expected.txt:
* LayoutTests/platform/glib/imported/w3c/web-platform-tests/svg/import/text-tselect-02-f-manual-expected.txt:
* LayoutTests/platform/glib/imported/w3c/web-platform-tests/svg/import/text-tselect-03-f-manual-expected.txt:
* LayoutTests/platform/gtk/svg/W3C-SVG-1.1/text-align-08-b-expected.txt:
* LayoutTests/platform/gtk/svg/W3C-SVG-1.1/text-tselect-02-f-expected.txt:
* LayoutTests/platform/gtk/svg/W3C-SVG-1.1/text-ws-01-t-expected.txt:
* LayoutTests/platform/ios/svg/W3C-SVG-1.1/text-altglyph-01-b-expected.txt:
* LayoutTests/platform/ios/svg/W3C-SVG-1.1/text-tselect-02-f-expected.txt:
* LayoutTests/platform/ios/svg/custom/text-whitespace-handling-expected.txt:
* LayoutTests/platform/ios/svg/text/font-size-below-point-five-expected.txt:
* LayoutTests/platform/ios/svg/text/text-align-01-b-expected.txt:
* LayoutTests/platform/ios/svg/text/text-hkern-expected.txt:
* LayoutTests/platform/ios/svg/text/text-tselect-02-f-expected.txt:
* LayoutTests/platform/ios/svg/text/text-ws-01-t-expected.txt:
* LayoutTests/platform/mac-sonoma/svg/W3C-SVG-1.1/text-tselect-02-f-expected.txt:
* LayoutTests/platform/wpe/svg/W3C-SVG-1.1/interact-order-01-b-expected.txt:
* LayoutTests/svg/text/textPathBoundsBug-expected.txt:
* LayoutTests/platform/ios/svg/text/text-align-01-b-expected.txt:
* LayoutTests/platform/ios/svg/text/text-altglyph-01-b-expected.txt:
* LayoutTests/platform/ios/svg/text/text-ws-01-t-expected.txt:
* LayoutTests/platform/ios/svg/W3C-SVG-1.1/text-ws-01-t-expected.txt:
* LayoutTests/svg/W3C-SVG-1.1/styling-css-02-b-expected.txt:
@Ahmad-S792 Ahmad-S792 removed the merging-blocked Applied to prevent a change from being merged label Aug 30, 2024
@Ahmad-S792 Ahmad-S792 force-pushed the eng/Replace-CRNL-by-space---dont-remove-altogether-when-xmlspacedefault branch from c7fb8b6 to 2fbcfd8 Compare August 30, 2024 15:00
newString = makeStringByReplacingAll(newString, '\t', ' ');
newString = makeStringByReplacingAll(newString, '\n', ' ');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really inefficient. We must have code somewhere to replace multiple characters in one traversal.

Is there an expectation that CRLF will get converted to a single space?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We fail following test case across browser - https://jsfiddle.net/asyrzuz2/, we use to do emptyString (""_s) before.

I will search through code to see, if there is a way to do all these via single go.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The WTF::String::simplifyWhitespace function is close to what we want. Especially because the comment mentions “all contiguous space characters will be consolidated” and that’s part of what simplifyWhitespace does. But it’s possible we’ll have to write a new function if we want something that’s super efficient and does exactly the right operation, and that is probably beyond the scope of what we should do in this pull request that is focused on correctness rather than efficiency. Scanning the string multiple times is not great, but doing so with the super-efficient “just check for one specific character” case might even be faster than scanning once with a less efficient inner loop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
SVG For bugs in the SVG implementation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants