Improve URL formatting with smart quote selection for data URIs#218
Merged
Conversation
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
Bundle ReportChanges will increase total bundle size by 380 bytes (2.15%) ⬆️. This is within the configured threshold ✅ Detailed changes
Affected Assets, Files, and Routes:view changes for bundle: formatCss-esmAssets Changed:
Files in
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
- Use `node.value ?? ''` to handle `string | null` - Reorder data: URL conditions to avoid negated-condition lint errors https://claude.ai/code/session_01PXdqvCto3sc2bUrPNQ4pdk
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.
Summary
Refactored URL printing logic to intelligently select quote styles for data URIs, ensuring proper formatting when URLs contain quotes.
Key Changes
print_url()function for better maintainabilityprint_string()to accept a configurable quote parameter (defaults to double quotes)%22when URL contains both quote typesImplementation 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