Skip to content

Improve URL formatting with smart quote selection for data URIs#218

Merged
bartveneman merged 4 commits into
mainfrom
claude/awesome-albattani-boelxs
Jun 8, 2026
Merged

Improve URL formatting with smart quote selection for data URIs#218
bartveneman merged 4 commits into
mainfrom
claude/awesome-albattani-boelxs

Conversation

@bartveneman

@bartveneman bartveneman commented Jun 8, 2026

Copy link
Copy Markdown
Member

Summary

Refactored URL printing logic to intelligently select quote styles for data URIs, ensuring proper formatting when URLs contain quotes.

Key Changes

  • Extracted URL printing logic into a new print_url() function for better maintainability
  • Updated print_string() to accept a configurable quote parameter (defaults to double quotes)
  • Implemented smart quote selection for data URIs:
    • Uses unquoted format when no quotes are present
    • Selects single quotes if URL contains double quotes
    • Selects double quotes if URL contains single quotes
    • Encodes double quotes as %22 when URL contains both quote types
  • Added comprehensive test coverage for data URI quote handling scenarios

Implementation Details

The new print_url() function detects data URIs via regex pattern matching and applies quote selection logic only to those URLs. Non-data URLs continue to use standard double-quote wrapping. This approach preserves backward compatibility while fixing edge cases with SVG data URIs that contain quoted attributes.

closes #217

claude added 3 commits June 8, 2026 19:03
Closes #217. Extracts URL printing into print_url(node: Url) and
safely chooses a quote style — single, double, or %22-encoded —
when the unquoted data: value contains quote characters that would
be illegal in an unquoted CSS URL token.

https://claude.ai/code/session_01PXdqvCto3sc2bUrPNQ4pdk
@codecov

codecov Bot commented Jun 8, 2026

Copy link
Copy Markdown

Bundle Report

Changes will increase total bundle size by 380 bytes (2.15%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
formatCss-esm 15.29kB 380 bytes (2.55%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: formatCss-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
index.js 380 bytes 13.62kB 2.87%

Files in index.js:

  • ./src/lib/index.ts → Total Size: 13.11kB

@codecov

codecov Bot commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.97%. Comparing base (1005430) to head (4db9359).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #218      +/-   ##
==========================================
+ Coverage   96.88%   96.97%   +0.09%     
==========================================
  Files           2        2              
  Lines         353      364      +11     
  Branches      130      136       +6     
==========================================
+ Hits          342      353      +11     
  Misses         10       10              
  Partials        1        1              

☔ 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.

- Use `node.value ?? ''` to handle `string | null`
- Reorder data: URL conditions to avoid negated-condition lint errors

https://claude.ai/code/session_01PXdqvCto3sc2bUrPNQ4pdk
@bartveneman bartveneman merged commit da76830 into main Jun 8, 2026
8 checks passed
@bartveneman bartveneman deleted the claude/awesome-albattani-boelxs branch June 8, 2026 19:38
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.

url() with quoted data: URL loses inner quotes, producing invalid CSS

2 participants