Skip to content

fix(css): keep "//" inside an unquoted url() when minifying - #5450

Merged
yusukebe merged 2 commits into
honojs:mainfrom
breken-ai:fix/css-minify-unquoted-url
Oct 16, 2026
Merged

yusukebe merged 2 commits into
honojs:mainfrom
breken-ai:fix/css-minify-unquoted-url

Conversation

@breken-ai

Copy link
Copy Markdown
Contributor

The CSS minifier treats // up to the end of the line as a comment. An unquoted url() has // in it (https://… or a protocol-relative //cdn…), so the rest of that line and the start of the next declaration get dropped:

const cls = css`
  background-image: url(https://example.com/a.png);
  color: red;
`
// before: .css-…{background-image:url(https:color:red}
// after:  .css-…{background-image:url(https://example.com/a.png);color:red}

This also happens when the URL is interpolated, e.g. url(${imageUrl}). Quoted url('…') already worked because quoted strings are kept as they are.

The fix adds unquoted url(...) to the tokens the minifier keeps unchanged, next to the quoted strings. Unquoted URLs can't contain quotes, whitespace or ), so the pattern stops at the closing parenthesis. It allows whitespace just inside the parentheses. // line comments everywhere else are still removed, and the existing "remove comments" case still passes.

The new preserve unquoted url case in src/helper/css/index.test.tsx fails on main with .css-123{background-image:url(https:mask-image:url(color:red} and passes with this change. vp test --project main passes (123 files), and tsc -p tsconfig.spec.json and vp check are clean.

The author should do the following, if applicable

  • Add tests
  • Run tests
  • pnpm run check:fix to format and lint the code
  • Add TSDoc/JSDoc to document the code (no public API change)

🤖 Generated with Claude Code

breken-ai and others added 2 commits September 25, 2026 18:41
The minifier strips "//" to the end of the line as a comment. An unquoted
url(https://...) or url(//cdn...) matched it too, so the rest of the
declaration and the next one were dropped:

  background-image: url(https://example.com/a.png);
  color: red;

became "background-image:url(https:color:red".

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.09%. Comparing base (90d02fb) to head (7c39521).
⚠️ Report is 46 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5450   +/-   ##
=======================================
  Coverage   80.09%   80.09%           
=======================================
  Files         159      159           
  Lines       11128    11129    +1     
  Branches     2377     2377           
=======================================
+ Hits         8913     8914    +1     
  Misses       2215     2215           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yusukebe yusukebe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@yusukebe

Copy link
Copy Markdown
Member

@breken-ai Thanks!

@yusukebe
yusukebe merged commit 2013fed into honojs:main Oct 16, 2026
19 checks passed
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.

2 participants