Skip to content

Commit e39acac

Browse files
committed
XMLSerializer.serializeToString() doesn't properly escape \n, \n and \t
https://bugs.webkit.org/show_bug.cgi?id=227844 Reviewed by Darin Adler. LayoutTests/imported/w3c: Rebaseline WPT test now that one more subtest is passing. * web-platform-tests/domparsing/XMLSerializer-serializeToString-expected.txt: Source/WebCore: XMLSerializer.serializeToString() doesn't properly escape \n, \n and \t. This is causing the "check XMLSerializer.serializeToString escapes attribute values for roundtripping" subtest to fail in WebKit on: http://wpt.live/domparsing/XMLSerializer-serializeToString.html Chrome and Firefox both escape these and pass this WPT subtest. The specification does not indicate we should escape those: - https://w3c.github.io/DOM-Parsing/#dfn-serializing-an-attribute-value But there is an open bug about this: - w3c/DOM-Parsing#59 No new tests, rebaselined existing test. * editing/MarkupAccumulator.cpp: (WebCore::elementCannotHaveEndTag): * editing/MarkupAccumulator.h: Canonical link: https://commits.webkit.org/239576@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@279815 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent a330317 commit e39acac

File tree

5 files changed

+53
-3
lines changed

5 files changed

+53
-3
lines changed

LayoutTests/imported/w3c/ChangeLog

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
2021-07-11 Chris Dumez <[email protected]>
2+
3+
XMLSerializer.serializeToString() doesn't properly escape \n, \n and \t
4+
https://bugs.webkit.org/show_bug.cgi?id=227844
5+
6+
Reviewed by Darin Adler.
7+
8+
Rebaseline WPT test now that one more subtest is passing.
9+
10+
* web-platform-tests/domparsing/XMLSerializer-serializeToString-expected.txt:
11+
112
2021-07-10 Chris Dumez <[email protected]>
213

314
document.readyState should be "complete" after calling DOMParser.parseFromString()

LayoutTests/imported/w3c/web-platform-tests/domparsing/XMLSerializer-serializeToString-expected.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ FAIL Check if an attribute with namespace and no prefix is serialized with the n
1212
PASS Check if the prefix of an attribute is replaced with another existing prefix mapped to the same namespace URI.
1313
FAIL Check if the prefix of an attribute is NOT preserved in a case where neither its prefix nor its namespace URI is not already used. assert_equals: expected "<r xmlns:xx=\"uri\" xmlns:ns1=\"uri2\" ns1:name=\"value\"/>" but got "<r xmlns:xx=\"uri\" p:name=\"value\" xmlns:p=\"uri2\"/>"
1414
FAIL Check if the prefix of an attribute is replaced with a generated one in a case where the prefix is already mapped to a different namespace URI. assert_equals: expected "<r xmlns:xx=\"uri\" xmlns:ns1=\"uri2\" ns1:name=\"value\"/>" but got "<r xmlns:xx=\"uri\" NS1:name=\"value\" xmlns:NS1=\"uri2\"/>"
15-
FAIL check XMLSerializer.serializeToString escapes attribute values for roundtripping assert_in_array: value "<root attr=\"\t\"/>" not in array ["<root attr=\"&#9;\"/>", "<root attr=\"&#x9;\"/>"]
15+
PASS check XMLSerializer.serializeToString escapes attribute values for roundtripping
1616
FAIL Check if attribute serialization takes into account of following xmlns:* attributes assert_equals: expected "<root xmlns:ns1=\"uri1\" ns1:foobar=\"value1\" xmlns:p=\"uri2\"/>" but got "<root p:foobar=\"value1\" xmlns:p=\"uri1\" xmlns:p=\"uri2\"/>"
1717
FAIL Check if attribute serialization takes into account of the same prefix declared in an ancestor element assert_equals: expected "<root xmlns:p=\"uri1\"><child xmlns:ns1=\"uri2\" ns1:foobar=\"v\"/></root>" but got "<root xmlns:p=\"uri1\"><child NS1:foobar=\"v\" xmlns:NS1=\"uri2\"/></root>"
1818
FAIL Check if start tag serialization drops element prefix if the namespace is same as inherited default namespace. assert_equals: expected "<root xmlns=\"u1\"><child xmlns:p=\"u1\"/></root>" but got "<root xmlns=\"u1\"><p:child xmlns:p=\"u1\"/></root>"

Source/WebCore/ChangeLog

+25
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
2021-07-11 Chris Dumez <[email protected]>
2+
3+
XMLSerializer.serializeToString() doesn't properly escape \n, \n and \t
4+
https://bugs.webkit.org/show_bug.cgi?id=227844
5+
6+
Reviewed by Darin Adler.
7+
8+
XMLSerializer.serializeToString() doesn't properly escape \n, \n and \t.
9+
10+
This is causing the "check XMLSerializer.serializeToString escapes attribute values for roundtripping" subtest to fail in WebKit on:
11+
http://wpt.live/domparsing/XMLSerializer-serializeToString.html
12+
13+
Chrome and Firefox both escape these and pass this WPT subtest.
14+
15+
The specification does not indicate we should escape those:
16+
- https://w3c.github.io/DOM-Parsing/#dfn-serializing-an-attribute-value
17+
But there is an open bug about this:
18+
- https://github.com/w3c/DOM-Parsing/issues/59
19+
20+
No new tests, rebaselined existing test.
21+
22+
* editing/MarkupAccumulator.cpp:
23+
(WebCore::elementCannotHaveEndTag):
24+
* editing/MarkupAccumulator.h:
25+
126
2021-07-10 Chris Dumez <[email protected]>
227

328
document.readyState should be "complete" after calling DOMParser.parseFromString()

Source/WebCore/editing/MarkupAccumulator.cpp

+12-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ static const EntityDescription entitySubstitutionList[] = {
6060
{ "&gt;", 4, EntityGt },
6161
{ "&quot;", 6, EntityQuot },
6262
{ "&nbsp;", 6, EntityNbsp },
63+
{ "&#9;", 4, EntityTab },
64+
{ "&#10;", 5, EntityLineFeed },
65+
{ "&#13;", 5, EntityCarriageReturn },
6366
};
6467

6568
enum EntitySubstitutionIndex {
@@ -69,11 +72,19 @@ enum EntitySubstitutionIndex {
6972
EntitySubstitutionGtIndex = 3,
7073
EntitySubstitutionQuotIndex = 4,
7174
EntitySubstitutionNbspIndex = 5,
75+
EntitySubstitutionTabIndex = 6,
76+
EntitySubstitutionLineFeedIndex = 7,
77+
EntitySubstitutionCarriageReturnIndex = 8,
7278
};
7379

7480
static const unsigned maximumEscapedentityCharacter = noBreakSpace;
7581
static const uint8_t entityMap[maximumEscapedentityCharacter + 1] = {
76-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
82+
0, 0, 0, 0, 0, 0, 0, 0, 0,
83+
EntitySubstitutionTabIndex, // '\t'.
84+
EntitySubstitutionLineFeedIndex, // '\n'.
85+
0, 0,
86+
EntitySubstitutionCarriageReturnIndex, // '\r'.
87+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
7788
EntitySubstitutionQuotIndex, // '"'.
7889
0, 0, 0,
7990
EntitySubstitutionAmpIndex, // '&'.

Source/WebCore/editing/MarkupAccumulator.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,16 @@ enum EntityMask {
4646
EntityGt = 0x0004,
4747
EntityQuot = 0x0008,
4848
EntityNbsp = 0x0010,
49+
EntityTab = 0x0020,
50+
EntityLineFeed = 0x0040,
51+
EntityCarriageReturn = 0x0080,
4952

5053
// Non-breaking space needs to be escaped in innerHTML for compatibility reason. See http://trac.webkit.org/changeset/32879
5154
// However, we cannot do this in a XML document because it does not have the entity reference defined (See the bug 19215).
5255
EntityMaskInCDATA = 0,
5356
EntityMaskInPCDATA = EntityAmp | EntityLt | EntityGt,
5457
EntityMaskInHTMLPCDATA = EntityMaskInPCDATA | EntityNbsp,
55-
EntityMaskInAttributeValue = EntityAmp | EntityLt | EntityGt | EntityQuot,
58+
EntityMaskInAttributeValue = EntityAmp | EntityLt | EntityGt | EntityQuot | EntityTab | EntityLineFeed | EntityCarriageReturn,
5659
EntityMaskInHTMLAttributeValue = EntityAmp | EntityQuot | EntityNbsp,
5760
};
5861

0 commit comments

Comments
 (0)