Repository navigation
Load a stylesheet url() with spaces, parentheses, inner quotes or an SVG data URI - #573
Merged
Merged
Conversation
jakejackson1
force-pushed
the
fix/552-stylesheet-url-quoting
branch
3 times, most recently
from
September 29, 2026 22:37
08d0f47 to
79d208d
Compare
…SVG data URI A background image named in a stylesheet was not loaded when its local path had spaces or parentheses, when the url() had whitespace inside its parentheses, or when it was a percent-encoded SVG data URI such as Bootstrap's form-select arrow. - url() is read as CSS reads it, in either quote or unquoted. A backslash before a quote, a parenthesis or whitespace is dropped; other backslashes are kept for Windows paths. - A local path that is not found as written is tried percent-decoded. - A data: URI is no longer resolved against the base path, and one that is not base64 is decoded directly instead of through PHP's data: wrapper or the HTTP client. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jakejackson1
force-pushed
the
fix/552-stylesheet-url-quoting
branch
from
September 29, 2026 23:45
79d208d to
c74ee6c
Compare
This was referenced Sep 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A background image named in a stylesheet's
url()was not drawn in these cases:url()url("sub dir/im (1).png"), a local file%20in the image loader. Nothing decoded them again, so the file was not found.url( a.png )form-selectarrow,url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' …%3e")Path::relativeToAbsolutePath()put the base path in front of the data URI. The://inside it madePath::isLocal()treat it as remote, so the HTTP client was asked for it and cURL rejected the URL.url("data:image/svg+xml;utf8,…")data:wrapper refuses a parameter without a value, such as;utf8.Part of #552 (Units, bug 10 in the audit). Part of #520.
Change
InlineStyleParser::processUrlsInCss()reads eachurl()in one pass, as CSS does:url(), and resolving\aor\das CSS hex escapes broke them.It writes
url('…')back with(,),{,}percent-encoded and;as the%ZZplaceholder, as before. The groups are possessive, so a long data URI does not exhaust PCRE's stack. The change stays insideprocessUrlsInCss(), soCssParseritself is not touched.AssetFetcher::fetchLocalContent()tries a local path percent-decoded when it is not found as written.Path::relativeToAbsolutePath()returns adata:URI unchanged.ImageProcessor::getImage()decodes a data URI that is not base64 itself, withrawurldecode(). It reads parameters before;base64as well.Two related problems are left for their own PRs:
styleattribute written in HTML, the SVG data URI is mangled before it reaches the CSS parser.url()with CSS escapes in a<style>block is split byCssLoader::resolveBackgroundUrls(), which runs first.Tests
StylesheetUrlTestrenders a stylesheet background for each case above, once withbackground-imageand once with thebackgroundshorthand. It checks that the image or SVG form is registered. The local image is copied tosub dir/bg (1).jpgin a temporary directory.InlineStyleParserTest::testProcessUrlschecks whatprocessUrlsInCss()writes for:;and braces, escaped quotes, parentheses and spaces, and a Windows path;url()s, upper caseURL(, and quoted and unquoted data URIs of 220 KB.StylesheetUrlSnapshotTest(stylesheet-url) shows each case under a caption saying what should be seen:url("img/bay eux.jpg")andurl( img/bay%20eux.jpg )both fill the box with the tapestry;Before this change, all four boxes are empty.
With the source change reverted, the new tests fail. The two long data URI cases also fail against the first, non-possessive version of the regex. No existing snapshot fixture changed.
Checks
composer test: OK. 4479 tests, 31 skipped for missing optional packages or ungenerated data. The snapshot suite ran with Imagick and Ghostscript.composer cs: clean.🤖 Generated with Claude Code