You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1) sanitize helper should allow a selection of svg tags
--- expected
+++ actual
@@ -1,4 +1,4 @@
-"<svg viewbox=\"0 0 100 100\" width=\"300\" height=\"100\" version=\"1.1\">
+"<svg width=\"300\" height=\"100\" version=\"1.1\">
<style>line,circle{stroke-width:3px;stroke:black;stroke-linecap:round}</style>
<style>test{stroke-width:3px;stroke:black;stroke-linecap:round}</style>
<g id=\"group1\" transform=\"translate(50,50)\">
As you can see viewbox is removed even though it is specified as a safe attribute.
We previously used the HTML4 sanitizer. Replacing HTML5 with HTML4 in the above code makes the test run perfectly.
I do not see why the behavior is different between both sanitizers.
We are currently using rails-html-sanitizer (1.6.0)
Context: I am currently working on updating to rails 7.1 which replaces HTML4 with HTML5 as default if supported. see dodona-edu/dodona#5031
The text was updated successfully, but these errors were encountered:
it"parses the same"doinput=%(<svg viewbox="0 0 100 100" width="300" height="100" version="1.1"></svg>)output=Nokogiri::HTML5.fragment(input).to_htmlassert_equal(input,output)end
yields
1) Failure:
TestSanitize#test_0002_parses the same [./issues/169-svg-viewbox.rb:54]:
--- expected
+++ actual
@@ -1 +1 @@
-"<svg viewbox=\"0 0 100 100\" width=\"300\" height=\"100\" version=\"1.1\"></svg>"
+"<svg viewBox=\"0 0 100 100\" width=\"300\" height=\"100\" version=\"1.1\"></svg>"
You'll note that the HTML5 parser emits viewBox where the HTML4 parser emits viewbox. This is the correct thing to do! The HTML4 parser incorrectly lowercased element names and attribute names in the SVG foreign context, so we should consider this to be an improvement.
If you update your allowlist to use viewBox instead of viewbox then the attribute (re-cased to viewBox) will be allowed by the sanitizer!
I hope all this makes sense -- if you've got followup questions, I'll try to answer.
We use the following sanitize function:
The following test fails:
with output:
As you can see
viewbox
is removed even though it is specified as a safe attribute.We previously used the HTML4 sanitizer. Replacing HTML5 with HTML4 in the above code makes the test run perfectly.
I do not see why the behavior is different between both sanitizers.
We are currently using
rails-html-sanitizer (1.6.0)
Context: I am currently working on updating to rails 7.1 which replaces HTML4 with HTML5 as default if supported. see dodona-edu/dodona#5031
The text was updated successfully, but these errors were encountered: