Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: ae8ba81610e4bf30c98fc9e376e50a0334d5fc1a
https://github.com/WebKit/WebKit/commit/ae8ba81610e4bf30c98fc9e376e50a0334d5fc1a
Author: Chris Dumez <[email protected]>
Date: 2026-08-04 (Tue, 04 Aug 2026)
Changed paths:
M
LayoutTests/imported/w3c/web-platform-tests/domparsing/DOMParser-parseFromString-xml-parsererror-expected.txt
M
LayoutTests/imported/w3c/web-platform-tests/domparsing/DOMParser-parseFromString-xml-parsererror.html
M Source/WebCore/xml/parser/XMLDocumentParser.cpp
M Source/WebCore/xml/parser/XMLDocumentParser.h
M Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp
Log Message:
-----------
[WPT] Fix "A lone surrogate is replaced with U+FFFD" subtest in
domparsing/DOMParser-parseFromString-xml-parsererror.html
https://bugs.webkit.org/show_bug.cgi?id=320858
Reviewed by Darin Adler.
When DOMParser.parseFromString() was given XML containing a lone (unpaired)
surrogate, XMLDocumentParser::doWrite() upconverted the string to UTF-16 and
passed it directly to libxml2. Lone surrogates are not valid XML characters,
so libxml2 rejected the entire document, leaving documentElement null instead
of producing any parse result.
Replace unpaired surrogates with U+FFFD before handing the input to libxml2,
so the parser does a best-effort parse instead of discarding everything. This
matches Firefox and Blink (https://crbug.com/40814739). The fragment path
(appendFragmentSource) was already unaffected because String::utf8() defaults
to LenientConversion, which maps unpaired surrogates to U+FFFD.
Change doWrite() to take its input as an rvalue reference and pass it to the
existing replaceUnpairedSurrogatesWithReplacementCharacter(String&&), whose fast
path simply moves the string along when there is no unpaired surrogate. That way
the common case allocates no buffer, copies no characters and does not even bump
a refcount (hasUnpairedSurrogate() is O(1) for 8-bit strings).
No new tests, updated and rebaselined existing test.
*
LayoutTests/imported/w3c/web-platform-tests/domparsing/DOMParser-parseFromString-xml-parsererror-expected.txt:
*
LayoutTests/imported/w3c/web-platform-tests/domparsing/DOMParser-parseFromString-xml-parsererror.html:
* Source/WebCore/xml/parser/XMLDocumentParser.cpp:
(WebCore::XMLDocumentParser::append):
* Source/WebCore/xml/parser/XMLDocumentParser.h:
* Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp:
(WebCore::XMLDocumentParser::doWrite):
Canonical link: https://commits.webkit.org/318609@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications