Skip to content

Fix CssInliner tokenizer crash on unquoted data: URLs containing parentheses#105

Draft
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-css-inliner-data-urls
Draft

Fix CssInliner tokenizer crash on unquoted data: URLs containing parentheses#105
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-css-inliner-data-urls

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 31, 2026

The CSS tokenizer's T_Url unquoted-content pattern ([^)]*?) stops at the first ) encountered, which breaks SVG data URIs that embed CSS functions like translate(), rgba(), or SVG url(#id) references. The premature stop leaves unparseable tokens (e.g. a lone ') that trigger an InvalidArgumentException.

Changes

  • src/Mail/CssInliner.php — Replace the unquoted URL pattern from [^)]*? to one that allows balanced (…) pairs:

    (?:[^()\\\]|\\\.|\((?:[^)\\\]|\\\.)*\))*
    

    Handles (…) groups one level deep — sufficient for all real-world SVG cases (translate(), rgba(), fill url() references).

  • tests/Mail/CssInliner.phpt — Add three regression tests for unquoted SVG data URIs containing parentheses in content (translate(), rgba(), url(#id)).

Example (previously crashing):

(new CssInliner)
    ->addCss("div { background: url(data:image/svg+xml,<svg><rect fill='rgba(255,0,0,0.5)'/></svg>); }")
    ->inline($html);
// InvalidArgumentException: Unexpected ''></svg>); }' at offset N in CSS.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/nette/di/zipball/e267934e7e7f55857058e19743f6732183adb4da
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/JjBn5P /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/Xe7gkm /usr/bin/composer install (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/wh9MV5 /usr/bin/composer install --no-interaction --prefer-dist --no-plugins (http block)
  • https://api.github.com/repos/nette/neon/zipball/aaea4aa3a8435934f1495ec5ecd5de623221a072
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/JjBn5P /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/Xe7gkm /usr/bin/composer install (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/wh9MV5 /usr/bin/composer install --no-interaction --prefer-dist --no-plugins (http block)
  • https://api.github.com/repos/nette/php-generator/zipball/4b54db13b80ac095cf26534d8c4097ab398658da
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/JjBn5P /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/Xe7gkm /usr/bin/composer install (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/wh9MV5 /usr/bin/composer install --no-interaction --prefer-dist --no-plugins (http block)
  • https://api.github.com/repos/nette/phpstan-rules/zipball/482780a38690d7ec5eadd181f5ae52f5ef000648
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/JjBn5P /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/wh9MV5 /usr/bin/composer install --no-interaction --prefer-dist --no-plugins (http block)
  • https://api.github.com/repos/nette/robot-loader/zipball/b662bf257bb22251ff590eefadd63da12ce90cbc
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/JjBn5P /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/Xe7gkm /usr/bin/composer install (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/wh9MV5 /usr/bin/composer install --no-interaction --prefer-dist --no-plugins (http block)
  • https://api.github.com/repos/nette/schema/zipball/bc3e09dcf65020fc60346a6d7e530ff93de01abb
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/JjBn5P /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/Xe7gkm /usr/bin/composer install (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/wh9MV5 /usr/bin/composer install --no-interaction --prefer-dist --no-plugins (http block)
  • https://api.github.com/repos/nette/tester/zipball/2f986e3ae04cd9287d335992c9d5b765bda52f44
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/JjBn5P /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/wh9MV5 /usr/bin/composer install --no-interaction --prefer-dist --no-plugins (http block)
  • https://api.github.com/repos/nette/tracy/zipball/a1671f4ff1969b8dc4a51f84e4cca646fa471d8b
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/JjBn5P /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/wh9MV5 /usr/bin/composer install --no-interaction --prefer-dist --no-plugins (http block)
  • https://api.github.com/repos/nette/utils/zipball/dd5725782de7b9d225d9375c51d211097ace82aa
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/JjBn5P /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/Xe7gkm /usr/bin/composer install (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/wh9MV5 /usr/bin/composer install --no-interaction --prefer-dist --no-plugins (http block)
  • https://api.github.com/repos/phpstan/extension-installer/zipball/85e90b3942d06b2326fba0403ec24fe912372936
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/JjBn5P /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/Xe7gkm /usr/bin/composer install (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/wh9MV5 /usr/bin/composer install --no-interaction --prefer-dist --no-plugins (http block)
  • https://api.github.com/repos/phpstan/phpstan/zipball/f8cdfd9421b7edb7686a2d150a234870464eac70
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/JjBn5P /usr/bin/composer install --no-interaction (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/Xe7gkm /usr/bin/composer install (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/wh9MV5 /usr/bin/composer install --no-interaction --prefer-dist --no-plugins (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI assigned Copilot and dg Mar 31, 2026
Copilot AI linked an issue Mar 31, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Fix handling of data URLs in CSS inliner Fix CssInliner tokenizer crash on unquoted data: URLs containing parentheses Mar 31, 2026
Copilot AI requested a review from dg March 31, 2026 17:28
Copilot finished work on behalf of dg March 31, 2026 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Css Inliner on data: backed urls

2 participants