Skip to content

XPath: Do not accept whitespace characters other than #x20, #x9, #xD, and #xA & fix normalize-space() - #13080

Merged
webkit-commit-queue merged 1 commit into
WebKit:mainfrom
Ahmad-S792:fix255841-domxpath
Apr 24, 2023
Merged

webkit-commit-queue merged 1 commit into
WebKit:mainfrom
Ahmad-S792:fix255841-domxpath

Conversation

@Ahmad-S792

@Ahmad-S792 Ahmad-S792 commented Apr 23, 2023 •

Copy link
Copy Markdown
Contributor

7e1bc9e

XPath: Do not accept whitespace characters other than #x20, #x9, #xD, and #xA & fix normalize-space()

https://bugs.webkit.org/show_bug.cgi?id=255841

Reviewed by Chris Dumez.

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

Merge: https://chromium.googlesource.com/chromium/src.git/+/01fd8522eaf35abdfa468f79333b350df96e1b62 &
https://chromium.googlesource.com/chromium/src.git/+/66c3b1b0ce745473f6478e1fa042d71f00ee9d47

This patch aligns WebKit with web-spec [1] & [2] and also fixes XML white spaces handling; #x20, #x9, #xD, and #xA.
We incorrectly handled other white spaces such as U+3000.

[1] https://www.w3.org/TR/1999/REC-xpath-19991116/#function-normalize-space
[2] https://www.w3.org/TR/1999/REC-xpath-19991116/#NT-ExprWhitespace

* Source/WebCore/xml/XPathFunctions.cpp:
(FunNormalizeSpace::evaluate):
* Source/WebCore/xml/XPathUtil.cpp:
(isXMLSpace): Introduce new bool function
* Source/WebCore/xml/XPathUtil.h: new bool function definition
* Source/WebCore/xml/XPathParser.cpp:
(Parser::skipWS): Use new 'isXMLSpace' function
* LayoutTests/imported/w3c/web-platform-tests/domxpath/lexical-structure-expected.txt: Rebaselined
* LayoutTests/imported/w3c/web-platform-tests/domxpath/fn-normalize-space-expected.txt: Rebaselined

Canonical link: https://commits.webkit.org/263311@main

6946f67

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

@Ahmad-S792 Ahmad-S792 added the XML For bugs in XML support other than XML DOM, including XSLT, XMLHTTPRequest, XML Parsing, etc. label Apr 23, 2023
@Ahmad-S792 Ahmad-S792 self-assigned this Apr 23, 2023
@Ahmad-S792
Ahmad-S792 requested a review from cdumez as a code owner April 23, 2023 14:40
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Apr 23, 2023
Comment thread Source/WebCore/xml/XPathUtil.cpp Resolved
@Ahmad-S792 Ahmad-S792 added request-merge-queue Request a pull request to be added to merge-queue once ready and removed merging-blocked Applied to prevent a change from being merged labels Apr 23, 2023
Comment thread Source/WebCore/xml/XPathFunctions.cpp Resolved
Comment thread Source/WebCore/xml/XPathUtil.cpp Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

XPath code seems like the wrong place fro this generic function. I know that Anne and Darin have been discussing related cleanup recently, not sure how closely that's related.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@annevk do you have a suggestion for a better location for this function?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ASCIICType.h is a good location I think, following the recent move of isHTMLSpace (plus renaming) there, but then the name should be either isHTTPWhitespace or isASCIIWhitespaceMinusFormFeed/isASCIIWhitespaceMinusFF. We'll primarily use it for HTTP, MIME types, and such, but apparently also for some XML-related features that are not covered by libxml.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will wait for @annevk's response and will work accordingly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think isASCIIWhitespaceMinusFormFeed is clearer name to me.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@aproskuryakov & @cdumez - I am able to do this in local build but my PR Git setup is bad and if I rebased then it will mess-up. I am happy to do follow-up to fix address this. My local branch is outdated and don't have @annevk's PR, so it will lead to merge conflict, if I do and rebasing tends to also mess-up this commit. Or I can close this PR and do new with all changes in one go.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Only issue is that @annevk has few open PRs, so I can do once all of them are merged and remove 'XMLSpace' from these functions and add them to 'ASCIICType.h' as suggested later.

Comment thread Source/WebCore/xml/XPathUtil.cpp Resolved
Comment thread Source/WebCore/xml/XPathUtil.h Resolved
@Ahmad-S792 Ahmad-S792 removed the request-merge-queue Request a pull request to be added to merge-queue once ready label Apr 24, 2023
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Apr 24, 2023
@Ahmad-S792 Ahmad-S792 removed the merging-blocked Applied to prevent a change from being merged label Apr 24, 2023
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Apr 24, 2023

@cdumez cdumez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@cdumez cdumez added merge-queue Applied to send a pull request to merge-queue and removed merging-blocked Applied to prevent a change from being merged labels Apr 24, 2023
… and #xA & fix normalize-space()

https://bugs.webkit.org/show_bug.cgi?id=255841

Reviewed by Chris Dumez.

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

Merge: https://chromium.googlesource.com/chromium/src.git/+/01fd8522eaf35abdfa468f79333b350df96e1b62 &
https://chromium.googlesource.com/chromium/src.git/+/66c3b1b0ce745473f6478e1fa042d71f00ee9d47

This patch aligns WebKit with web-spec [1] & [2] and also fixes XML white spaces handling; #x20, #x9, #xD, and #xA.
We incorrectly handled other white spaces such as U+3000.

[1] https://www.w3.org/TR/1999/REC-xpath-19991116/#function-normalize-space
[2] https://www.w3.org/TR/1999/REC-xpath-19991116/#NT-ExprWhitespace

* Source/WebCore/xml/XPathFunctions.cpp:
(FunNormalizeSpace::evaluate):
* Source/WebCore/xml/XPathUtil.cpp:
(isXMLSpace): Introduce new bool function
* Source/WebCore/xml/XPathUtil.h: new bool function definition
* Source/WebCore/xml/XPathParser.cpp:
(Parser::skipWS): Use new 'isXMLSpace' function
* LayoutTests/imported/w3c/web-platform-tests/domxpath/lexical-structure-expected.txt: Rebaselined
* LayoutTests/imported/w3c/web-platform-tests/domxpath/fn-normalize-space-expected.txt: Rebaselined

Canonical link: https://commits.webkit.org/263311@main
@webkit-commit-queue

Copy link
Copy Markdown
Collaborator

Committed 263311@main (7e1bc9e): https://commits.webkit.org/263311@main

Reviewed commits have been landed. Closing PR #13080 and removing active labels.

@webkit-commit-queue
webkit-commit-queue merged commit 7e1bc9e into WebKit:main Apr 24, 2023
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Apr 24, 2023
@Ahmad-S792
Ahmad-S792 deleted the fix255841-domxpath branch May 25, 2023 21:09
webkit-commit-queue pushed a commit to annevk/WebKit that referenced this pull request Jul 24, 2023
https://bugs.webkit.org/show_bug.cgi?id=255872
rdar://108738795

Reviewed by Darin Adler.

It turns out that JSON, HTTP, and XML all use the same whitespace
definition, so let's make them share it. Also correct an existing
comment for that function as \v is not part of isASCIIWhitespace(), but
\f is.

Furthermore, remove the "optimization" from these whitespace functions
per a comment from Chris Dumez at
WebKit#13080 (comment):

> Just verified out of curiosity and llvm does generate the same code
> with -O2 (tried both arm64 and x86_64):
>
> isXMLSpace1(char):                       // @isXMLSpace1(char)
>         mov     x8, WebKit#9728                       // =0x2600
>         and     w9, w0, #0xff
>         movk    x8, WebKit#1, lsl WebKit#32
>         cmp     w9, WebKit#33
>         cset    w9, lo
>         lsr     x8, x8, x0
>         and     w0, w9, w8
>         ret
> isXMLSpace2(char):                       // @isXMLSpace2(char)
>         mov     x8, WebKit#9728                       // =0x2600
>         and     w9, w0, #0xff
>         movk    x8, WebKit#1, lsl WebKit#32
>         cmp     w9, WebKit#33
>         cset    w9, lo
>         lsr     x8, x8, x0
>         and     w0, w9, w8
>         ret
>
> Ahmad-S792 Let's simplify the code then.

* Source/WTF/wtf/ASCIICType.h:
(WTF::isASCIIWhitespace):
(WTF::isJSONOrHTTPOrXMLWhitespace):
(WTF::isJSONOrHTTPWhitespace): Deleted.
* Source/WTF/wtf/JSONValues.cpp:
(WTF::JSONImpl::Value::parseJSON):
* Source/WTF/wtf/text/StringToIntegerConversion.h:
* Source/WebCore/Modules/cache/DOMCache.cpp:
(WebCore::hasResponseVaryStarHeaderValue):
* Source/WebCore/Modules/cache/DOMCacheEngine.cpp:
(WebCore::DOMCacheEngine::queryCacheMatch):
* Source/WebCore/Modules/fetch/FetchBodyConsumer.cpp:
(WebCore::parseParameters):
(WebCore::parseMIMEType):
(WebCore::FetchBodyConsumer::packageFormData):
* Source/WebCore/Modules/fetch/FetchHeaders.cpp:
(WebCore::canWriteHeader):
(WebCore::appendToHeaderMap):
(WebCore::FetchHeaders::set):
(WebCore::FetchHeaders::filterAndFill):
* Source/WebCore/mathml/MathMLPresentationElement.cpp:
(WebCore::MathMLPresentationElement::parseMathMLLength):
* Source/WebCore/mathml/MathMLTokenElement.cpp:
(WebCore::MathMLTokenElement::convertToSingleCodePoint):
* Source/WebCore/page/csp/ContentSecurityPolicyDirectiveList.cpp:
(WebCore::ContentSecurityPolicyDirectiveList::parse):
* Source/WebCore/platform/ReferrerPolicy.cpp:
(WebCore::parseReferrerPolicy):
* Source/WebCore/platform/network/DataURLDecoder.cpp:
(WebCore::DataURLDecoder::DecodeTask::process):
* Source/WebCore/platform/network/HTTPParsers.cpp:
(WebCore::parseContentTypeOptionsHeader):
(WebCore::parseClearSiteDataHeader):
(WebCore::parseRange):
(WebCore::parseCrossOriginResourcePolicyHeader):
* Source/WebCore/platform/network/HTTPParsers.h:
(WebCore::addToAccessControlAllowList):
* Source/WebCore/platform/network/ParsedContentType.cpp:
(WebCore::skipSpaces):
(WebCore::parseToken):
(WebCore::ParsedContentType::create):
(WebCore::ParsedContentType::setContentType):
* Source/WebCore/platform/network/ResourceResponseBase.cpp:
(WebCore::ResourceResponseBase::containsInvalidHTTPHeaders const):
* Source/WebCore/platform/network/TimingAllowOrigin.cpp:
(WebCore::passesTimingAllowOriginCheck):
* Source/WebCore/xml/XMLHttpRequest.cpp:
(WebCore::XMLHttpRequest::setRequestHeader):
* Source/WebCore/xml/XPathFunctions.cpp:
(WebCore::XPath::FunNormalizeSpace::evaluate const):
* Source/WebCore/xml/XPathParser.cpp:
(WebCore::XPath::Parser::skipWS):
* Source/WebCore/xml/XPathUtil.cpp:
(WebCore::XPath::isXMLSpace): Deleted.
* Source/WebCore/xml/XPathUtil.h:
* Source/WebKit/NetworkProcess/cache/CacheStorageEngineCache.cpp:
(WebKit::CacheStorage::updateVaryInformation):
* Source/WebKit/NetworkProcess/soup/WebSocketTaskSoup.cpp:
(WebKit::WebSocketTask::WebSocketTask):
* Source/WebKit/NetworkProcess/storage/CacheStorageRecord.h:
(WebKit::CacheStorageRecordInformation::updateVaryHeaders):
* Source/WebKit/WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::shouldSkipDecidePolicyForResponse const):

Canonical link: https://commits.webkit.org/266253@main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

XML For bugs in XML support other than XML DOM, including XSLT, XMLHTTPRequest, XML Parsing, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants