Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[css-values] URL-encoding strings #9146

Open
valtlai opened this issue Aug 3, 2023 · 0 comments
Open

[css-values] URL-encoding strings #9146

valtlai opened this issue Aug 3, 2023 · 0 comments

Comments

@valtlai
Copy link
Contributor

valtlai commented Aug 3, 2023

Spec: https://www.w3.org/TR/css-values/

When inlining SVG, some characters need to be URL-encoded. For example, the # (%23) in the following:

.lorem {
  background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg"><rect fill="%23fd0" width="100%" height="100%"/></svg>');
}

We could avoid that manual escaping if there was a sufficient function in CSS:

.lorem {
  --svg: '<svg xmlns="http://www.w3.org/2000/svg"><rect fill="#fd0" width="100%" height="100%"/></svg>';
  background: src(concat('data:image/svg+xml,' url-encode(var(--svg)));
}

Here the function url-encode() (name TBD) takes a string and returns the URL-encoded version of it. The resulting string can be then safely concatenated to the data URL. For concat(), see #542.

So, should we define a new CSS function that URL-encodes a string? Are there any other use cases?

@valtlai valtlai changed the title [css-values] URL encoding strings [css-values] URL-encoding strings Aug 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants