Skip to content

Commit

Permalink
Add checks for the case of data url in SVGURIReference.
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=149460

Reviewed by Said Abou-Hallawa.

Add check for the case of data url in SVGURIReference.
The test still fails as it returns nullptr for the element in data url case in
SVGURIReference::targetElementFromIRIString(). We need to load the data url in
a Document to be able to get the target element for the corresponding fragement
ID.

* LayoutTests/TestExpectations:
* Source/WebCore/svg/SVGURIReference.cpp:
(WebCore::SVGURIReference::targetElementFromIRIString):
(WebCore::SVGURIReference::haveLoadedRequiredResources const):
* Source/WebCore/svg/SVGUseElement.cpp:
(WebCore::SVGUseElement::updateExternalDocument):

Canonical link: https://commits.webkit.org/285321@main
  • Loading branch information
ziransun committed Oct 17, 2024
1 parent 8b7209b commit 04332ce
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
3 changes: 1 addition & 2 deletions LayoutTests/TestExpectations
Original file line number Diff line number Diff line change
Expand Up @@ -5983,8 +5983,7 @@ imported/w3c/web-platform-tests/css/filter-effects/svg-external-filter-resource.
imported/w3c/web-platform-tests/css/filter-effects/svg-mutation-filter-used-by-mask.html [ ImageOnlyFailure ]
imported/w3c/web-platform-tests/css/filter-effects/will-change-blur-filter-under-clip.html [ ImageOnlyFailure ]

[ Release ] imported/w3c/web-platform-tests/css/filter-effects/svg-feimage-002.html [ ImageOnlyFailure ]
webkit.org/b/149460 [ Debug ] imported/w3c/web-platform-tests/css/filter-effects/svg-feimage-002.html [ Crash ]
imported/w3c/web-platform-tests/css/filter-effects/svg-feimage-002.html [ ImageOnlyFailure ]

imported/w3c/web-platform-tests/content-security-policy/script-src/ [ DumpJSConsoleLogInStdErr ]

Expand Down
12 changes: 11 additions & 1 deletion Source/WebCore/svg/SVGURIReference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ auto SVGURIReference::targetElementFromIRIString(const String& iri, const TreeSc
return { externalDocument->getElementById(id), WTFMove(id) };
}

if (url.protocolIsData()) {
// FIXME: We need to load the data url in a Document to be able to get the target element.
if (!equalIgnoringFragmentIdentifier(url, document->url()))
return { nullptr, WTFMove(id) };
}

// Exit early if the referenced url is external, and we have no externalDocument given.
if (isExternalURIReference(iri, document))
return { nullptr, WTFMove(id) };
Expand All @@ -115,7 +121,11 @@ auto SVGURIReference::targetElementFromIRIString(const String& iri, const TreeSc

bool SVGURIReference::haveLoadedRequiredResources() const
{
if (href().isEmpty() || !isExternalURIReference(href(), contextElement().protectedDocument()))
if (href().isEmpty())
return true;
if (contextElement().protectedDocument()->completeURL(href()).protocolIsData())
return true;
if (!isExternalURIReference(href(), contextElement().protectedDocument()))
return true;
return errorOccurred() || haveFiredLoadEvent();
}
Expand Down
3 changes: 3 additions & 0 deletions Source/WebCore/svg/SVGUseElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,9 @@ void SVGUseElement::updateExternalDocument()
{
URL externalDocumentURL;
Ref<Document> document = this->document();
// FIXME: This early exit should be removed once the ASSERT(!url.protocolIsData()) is removed from isExternalURIReference().
if (document->completeURL(href()).protocolIsData())
return;
if (isConnected() && isExternalURIReference(href(), document)) {
externalDocumentURL = document->completeURL(href());
if (!externalDocumentURL.hasFragmentIdentifier())
Expand Down

0 comments on commit 04332ce

Please sign in to comment.