Bug 44047 - Stylesheets that use local references are treated as local to the SVG document
Summary: Stylesheets that use local references are treated as local to the SVG document
Alias: None
Product: WebKit
Classification: Unclassified
Component: SVG (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC Linux
: P2 Normal
Assignee: Nobody
Depends on:
Reported: 2010-08-16 01:24 PDT by Daniel Holbert
Modified: 2022-06-14 12:50 PDT (History)
6 users (show)

See Also:

testcase 1 (1.04 KB, image/svg+xml)
2010-08-16 01:24 PDT, Daniel Holbert
no flags Details
WIP patch (5.25 KB, patch)
2010-08-26 12:52 PDT, Rob Buis
no flags Details | Formatted Diff | Diff
Safari 15.5 matches other browsers (566.56 KB, image/png)
2022-06-13 13:27 PDT, Ahmad Saleem
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Holbert 2010-08-16 01:24:58 PDT
Created attachment 64476 [details]
testcase 1

STEPS TO REPRODUCE:  Load attached testcase.
EXPECTED RESULTS:    The teal line should have no arrowhead.
ACTUAL RESULTS:      In WebKit, the teal line has an arrowhead.

NOTE: My example uses a data URI for the stylesheet, for simplicity of bug-attaching.  However, this happens for "real" (non-data-URI) external stylesheets as well.

EXPLANATION: In the testcase, the reference "url(#myMarker)" ends up looking for that node in our our SVG document. This is incorrect -- per specification, that identifier should use the URI of the stylesheet instead.  See in particular:
In order to create modular style sheets that are not dependent on the absolute
location of a resource, authors may use relative URIs. Relative URIs (as defined
in [RFC3986]) are resolved to full URIs using a base URI. RFC 3986, section 5,
defines the normative algorithm for this process. For CSS style sheets, the base
URI is that of the style sheet, not that of the source document.

Filing this based on the following (invalid) Mozilla bugs:
(they were filed for Mozilla *not* placing the arrowhead, but that's in fact the correct behavior)
See those bugs for more discussion of this issue.

Recent Firefox & Opera both give EXPECTED RESULTS.  Webkit* gives ACTUAL RESULTS.

* I tested these WebKit-based browsers on Ubuntu 10.04:
    Chromium 6.0.495.0 (56150)
    Midori 0.2.2 (WebKitGTK+ 1.1.21)
Comment 1 Rob Buis 2010-08-26 12:52:18 PDT
Created attachment 65602 [details]
WIP patch
Comment 2 Rob Buis 2010-08-26 12:58:27 PDT
It seems to me these checks can be done on three levels:

1 at the css parser level, perfectly possible but computed values for url(#foo) will not
show and that is not what I see in Opera and FF.

2 at the css style selector level, checking the stylesheet baseURL with the doc URL seems
not reliable though when doing run-webkit-tests, I suspect the static cache in

3 at rendering time, this has the drawback of slowing down painting.

Since 2 seems the most reasonable (computed values ok and no painting speed loss) I went for
that in my WIP patch. I think right now checking for data: is enough as xml-stylesheet referncing
an external stylesheet seems to wok in all implementations (see for instance LayoutTests/svg/batik/paints/gradientLimit.svg).

I have a testcase handy, just wanted to show the patch and maybe get some feedback on whether this is the right approach.

Comment 3 Nikolas Zimmermann 2010-08-27 01:05:37 PDT
Comment on attachment 65602 [details]
WIP patch

 +              parsedValue = CSSPrimitiveValue::create(m_styleSheet->completeURL(value->string), CSSPrimitiveValue::CSS_URI);
I'm not sure about this approach, as CSSParser.cpp contains lots of

        // FIXME: The completeURL call should be done when using the CSSImageValue,
        // not when creating it.

for each instance of the code which uses m_styleSheet->completeURL(value->string)
That indicates it's not the right way to go for new code.

 +                     if (svgPaint->uri().startsWith("data:"))
I don't get that check? Where is that used? What implications does it have if you wouldn't handle it here?WebCore/css/SVGCSSStyleSelector.cpp:346
 +              if (s.startsWith("data:"))

 +              if (s.startsWith("data:"))

 +              if (s.startsWith("data:"))

 +              if (s.startsWith("data:"))

 +              if (s.startsWith("data:"))

 +              if (s.startsWith("data:"))

If it's somehow absolutely needed (can't tell w/o a test or ChangeLog), then you should at least refactor it into a shared function.
Comment 4 Ahmad Saleem 2022-06-13 13:27:12 PDT
Created attachment 460210 [details]
Safari 15.5 matches other browsers

I am unable to reproduce the "Expected Results" in Safari 15.5 on macOS 12.4 but it matches all other browsers (Chrome Canary 105 and Firefox Nightly 103).

I think it got fixed along the lines or spec changed and all other browsers started matching Webkit. Can this be marked as "RESOLVED INVALID" and "RESOLVED CONFIGURATION CHANGED". Thanks!
Comment 5 Ryosuke Niwa 2022-06-14 12:50:42 PDT
Thanks for confirming. I've checked as well, and this indeed seem to be interoperable now.