-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Encoding svg dataurl #3418
Comments
Well that's bacause |
Ok, it is effective but not not a legal character according to w3c. I understand how it saves some data not to encode, but since it does not validate, is there a way around this? |
Since you haven't provided any information about how to reproduce this, I'm going to make something up: <!doctype html>
<img src="data:image/svg+xml,<svg width='100' height='100' xmlns='http://www.w3.org/2000/svg'><rect width='100' height='100' fill='red'/></svg>"> That should show up as a red square. That appears to work fine in Chrome, Safari, and Firefox. Which specific browsers does this HTML not work in for you (including the version information)? Alternatively, please provide enough information to reproduce an incorrect rendering given a test case of yours (along with a specific browser). If you need base64 encoding because some additional tooling you're using needs data URLs to be in base64 form, then you can explicitly use the base64 loader yourself: https://esbuild.github.io/content-types/#base64. |
The problem is that the characters < and > are not encoded and that is not valid in the src-element. To validate that: paste the following into the validator; https://validator.w3.org/nu/#textarea:
as I see it, < and > are supported unencoded by all modern browsers, but it is still not legal html.
|
I'm confused. How did you even get this HTML in the first place? All the HTML templating languages I've used automatically escape Regardless, you didn't respond to my previous post:
|
I'm closing this issue due to lack of a follow-up response. AFAIK the data URLs that esbuild generates work fine in all known browsers. It is not esbuild's job to pre-escape the characters in its data URLs for all possible contexts that they might be used in. Instead, you should be properly escaping data for the relevant context when building HTML using string concatenation. |
This is not what esbuild will encode though, esbuild will not encode the < and > as it is done in this example, nor would it convert double quotes to single quotes if they are present in the .svg file that it pulls out, so while this may work, it is not what esbuild would output. Is it expected that the content of an '.svg' files that is targeted should already be encoded correctly ? As an example, esbuild will encode esbuild/internal/helpers/dataurl.go Lines 49 to 50 in 4e11b50
|
The only escaping that the If you have a specific example of a browser that esbuild's data URLs doesn't work with, then please post that information here (the browser name, version, operating system, and any other information necessary to reproduce the problem). Without a demonstration that esbuild's |
Ok, if that's the goal and not to follow the standard defined for data urls then I guess there is no issue. |
The encoding for svgs when using loader dataurl does not validate using validator.w3org.
Error: "Bad value for attribute src on element img: Illegal character in scheme data: < is not allowed."
I.e. the characters < and > are not encoded in the data url.
The solution should be to encode < and >.
Another solution would be to have the option to use base64-encoding for svgs
The text was updated successfully, but these errors were encountered: