fix: inline escaped SVG data-uri make canvas tainted in Safari between iOS 10-11.2 #2683
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
This PR fixes/implements the following bugs/features
What is escaped SVG data-uri?
Before, developers can put inline SVG data-uri into CSS like this.
However, modern browsers do not support some characters like ",%,#,{,},<,> in the data-uri anymore. Using base64 encoded SVG data-uri can bypass this problem, but it is not a good practice since the length will increase by 1/3.
The best practice (also with best compatibility) is to 'encodeURIComponent' the SVG data-uri. After that, the code like this:
demo
What is the problem with Safari?
Safari between iOS 10.3-11.2 will need the 'crossorigin' attribute on the img tag to load not only base64 encoded data-uri but all kinds of data-uri.
#1797 tried to fix this problem, but I found when the data-uri isn't base 64 the problem still exists.
In my humble opinion, I suggest load every data-uri with the 'crossorigin' attribute.
Test plan (required)
Test case was added in the
tests/reftests/background/svg.html
.Closing issues
Fixes this comment: #1575 (comment)