File tree 3 files changed +22
-1
lines changed
3 files changed +22
-1
lines changed Original file line number Diff line number Diff line change 1
1
## 1.6.0.rc1 / 2023-05-24
2
2
3
- * Sanitizers that use an HTML5 parser are now available on platforms supported by
3
+ * HTML5 standards-compliant sanitizers are now available on platforms supported by
4
4
Nokogiri::HTML5. These are available as:
5
5
6
6
- ` Rails::HTML5::FullSanitizer `
13
13
Note that for symmetry ` Rails::HTML4::Sanitizer ` is also added, though its behavior is identical
14
14
to the vendor class methods on ` Rails::HTML::Sanitizer ` .
15
15
16
+ Users may call ` Rails::HTML::Sanitizer.best_supported_vendor ` to get back the HTML5 vendor if it's
17
+ supported, else the legacy HTML4 vendor.
18
+
16
19
* Mike Dalessio*
17
20
18
21
* Module namespaces have changed, but backwards compatibility is provided by aliases.
Original file line number Diff line number Diff line change @@ -9,6 +9,10 @@ def html5_support?
9
9
10
10
@html5_support = Loofah . respond_to? ( :html5_support? ) && Loofah . html5_support?
11
11
end
12
+
13
+ def best_supported_vendor
14
+ html5_support? ? Rails ::HTML5 ::Sanitizer : Rails ::HTML4 ::Sanitizer
15
+ end
12
16
end
13
17
14
18
def sanitize ( html , options = { } )
Original file line number Diff line number Diff line change @@ -17,6 +17,20 @@ def test_html_scrubber_class_names
17
17
assert ( Rails ::Html ::Sanitizer )
18
18
end
19
19
20
+ def test_best_supported_vendor_when_html5_is_not_supported_returns_html4
21
+ Rails ::HTML ::Sanitizer . stub ( :html5_support? , false ) do
22
+ assert_equal ( Rails ::HTML4 ::Sanitizer , Rails ::HTML ::Sanitizer . best_supported_vendor )
23
+ end
24
+ end
25
+
26
+ def test_best_supported_vendor_when_html5_is_supported_returns_html5
27
+ skip ( "no HTML5 support on this platform" ) unless Rails ::HTML ::Sanitizer . html5_support?
28
+
29
+ Rails ::HTML ::Sanitizer . stub ( :html5_support? , true ) do
30
+ assert_equal ( Rails ::HTML5 ::Sanitizer , Rails ::HTML ::Sanitizer . best_supported_vendor )
31
+ end
32
+ end
33
+
20
34
def test_html4_sanitizer_alias_full
21
35
assert_equal ( Rails ::HTML4 ::FullSanitizer , Rails ::HTML ::FullSanitizer )
22
36
assert_equal ( "Rails::HTML4::FullSanitizer" , Rails ::HTML ::FullSanitizer . name )
You can’t perform that action at this time.
0 commit comments