sanitize 7.0.0 → 7.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sanitize
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.0
4
+ version: 7.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Grove
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2024-12-30 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: crass
@@ -15,32 +15,32 @@ dependencies:
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: 1.0.2
18
+ version: 1.0.8
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
- version: 1.0.2
25
+ version: 1.0.8
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: nokogiri
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 1.16.8
32
+ version: 1.19.7
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: 1.16.8
39
+ version: 1.19.7
40
40
  description: |
41
41
  Sanitize is an allowlist-based HTML and CSS sanitizer. It removes all HTML
42
42
  and/or CSS from a string except the elements, attributes, and properties you
43
- choose to allow.'
43
+ choose to allow.
44
44
  email: ryan@wonko.com
45
45
  executables: []
46
46
  extensions: []
@@ -62,18 +62,6 @@ files:
62
62
  - lib/sanitize/transformers/clean_doctype.rb
63
63
  - lib/sanitize/transformers/clean_element.rb
64
64
  - lib/sanitize/version.rb
65
- - test/common.rb
66
- - test/test_clean_comment.rb
67
- - test/test_clean_css.rb
68
- - test/test_clean_doctype.rb
69
- - test/test_clean_element.rb
70
- - test/test_config.rb
71
- - test/test_malicious_css.rb
72
- - test/test_malicious_html.rb
73
- - test/test_parser.rb
74
- - test/test_sanitize.rb
75
- - test/test_sanitize_css.rb
76
- - test/test_transformers.rb
77
65
  homepage: https://github.com/rgrove/sanitize/
78
66
  licenses:
79
67
  - MIT
@@ -88,14 +76,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
88
76
  requirements:
89
77
  - - ">="
90
78
  - !ruby/object:Gem::Version
91
- version: 3.1.0
79
+ version: 3.2.0
92
80
  required_rubygems_version: !ruby/object:Gem::Requirement
93
81
  requirements:
94
82
  - - ">="
95
83
  - !ruby/object:Gem::Version
96
84
  version: '0'
97
85
  requirements: []
98
- rubygems_version: 3.6.2
86
+ rubygems_version: 4.0.20
99
87
  specification_version: 4
100
88
  summary: Allowlist-based HTML and CSS sanitizer.
101
89
  test_files: []
data/test/common.rb DELETED
@@ -1,4 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "minitest/autorun"
4
- require "sanitize"
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "common"
4
-
5
- describe "Sanitize::Transformers::CleanComment" do
6
- make_my_diffs_pretty!
7
- parallelize_me!
8
-
9
- describe "when :allow_comments is false" do
10
- before do
11
- @s = Sanitize.new(allow_comments: false, elements: ["div"])
12
- end
13
-
14
- it "should remove comments" do
15
- _(@s.fragment("foo <!-- comment --> bar")).must_equal "foo bar"
16
- _(@s.fragment("foo <!-- ")).must_equal "foo "
17
- _(@s.fragment("foo <!-- - -> bar")).must_equal "foo "
18
- _(@s.fragment("foo <!--\n\n\n\n-->bar")).must_equal "foo bar"
19
- _(@s.fragment("foo <!-- <!-- <!-- --> --> -->bar")).must_equal "foo --&gt; --&gt;bar"
20
- _(@s.fragment("foo <div <!-- comment -->>bar</div>")).must_equal "foo <div>&gt;bar</div>"
21
-
22
- # Special case: the comment markup is inside a <script>, which makes it
23
- # text content and not an actual HTML comment.
24
- _(@s.fragment("<script><!-- comment --></script>")).must_equal ""
25
-
26
- _(Sanitize.fragment("<script><!-- comment --></script>", allow_comments: false, elements: ["script"]))
27
- .must_equal "<script><!-- comment --></script>"
28
- end
29
- end
30
-
31
- describe "when :allow_comments is true" do
32
- before do
33
- @s = Sanitize.new(allow_comments: true, elements: ["div"])
34
- end
35
-
36
- it "should allow comments" do
37
- _(@s.fragment("foo <!-- comment --> bar")).must_equal "foo <!-- comment --> bar"
38
- _(@s.fragment("foo <!-- ")).must_equal "foo <!-- -->"
39
- _(@s.fragment("foo <!-- - -> bar")).must_equal "foo <!-- - -> bar-->"
40
- _(@s.fragment("foo <!--\n\n\n\n-->bar")).must_equal "foo <!--\n\n\n\n-->bar"
41
- _(@s.fragment("foo <!-- <!-- <!-- --> --> -->bar")).must_equal "foo <!-- <!-- <!-- --> --&gt; --&gt;bar"
42
- _(@s.fragment("foo <div <!-- comment -->>bar</div>")).must_equal "foo <div>&gt;bar</div>"
43
-
44
- _(Sanitize.fragment("<script><!-- comment --></script>", allow_comments: true, elements: ["script"]))
45
- .must_equal "<script><!-- comment --></script>"
46
- end
47
- end
48
- end
@@ -1,68 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "common"
4
-
5
- describe "Sanitize::Transformers::CSS::CleanAttribute" do
6
- make_my_diffs_pretty!
7
- parallelize_me!
8
-
9
- before do
10
- @s = Sanitize.new(Sanitize::Config::RELAXED)
11
- end
12
-
13
- it "should sanitize CSS properties in style attributes" do
14
- _(@s.fragment(%[
15
- <div style="color: #fff; width: expression(alert(1)); /* <-- evil! */"></div>
16
- ].strip)).must_equal %(
17
- <div style="color: #fff; /* <-- evil! */"></div>
18
- ).strip
19
- end
20
-
21
- it "should remove the style attribute if the sanitized CSS is empty" do
22
- _(@s.fragment('<div style="width: expression(alert(1))"></div>'))
23
- .must_equal "<div></div>"
24
- end
25
- end
26
-
27
- describe "Sanitize::Transformers::CSS::CleanElement" do
28
- make_my_diffs_pretty!
29
- parallelize_me!
30
-
31
- before do
32
- @s = Sanitize.new(Sanitize::Config::RELAXED)
33
- end
34
-
35
- it "should sanitize CSS stylesheets in <style> elements" do
36
- html = %[
37
- <style>@import url(evil.css);
38
- /* Yay CSS! */
39
- .foo { color: #fff; }
40
- #bar { background: url(yay.jpg); bogus: wtf; }
41
- .evil { width: expression(xss()); }
42
-
43
- @media screen (max-width:480px) {
44
- .foo { width: 400px; }
45
- #bar:not(.baz) { height: 100px; }
46
- }
47
- </style>
48
- ].strip
49
-
50
- _(@s.fragment(html)).must_equal %[
51
- <style>
52
- /* Yay CSS! */
53
- .foo { color: #fff; }
54
- #bar { background: url(yay.jpg); }
55
- .evil { }
56
-
57
- @media screen (max-width:480px) {
58
- .foo { width: 400px; }
59
- #bar:not(.baz) { height: 100px; }
60
- }
61
- </style>
62
- ].strip
63
- end
64
-
65
- it "should remove the <style> element if the sanitized CSS is empty" do
66
- _(@s.fragment("<style></style>")).must_equal ""
67
- end
68
- end
@@ -1,72 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "common"
4
-
5
- describe "Sanitize::Transformers::CleanDoctype" do
6
- make_my_diffs_pretty!
7
- parallelize_me!
8
-
9
- describe "when :allow_doctype is false" do
10
- before do
11
- @s = Sanitize.new(allow_doctype: false, elements: ["html"])
12
- end
13
-
14
- it "should remove doctype declarations" do
15
- _(@s.document("<!DOCTYPE html><html>foo</html>")).must_equal "<html>foo</html>"
16
- _(@s.fragment("<!DOCTYPE html>foo")).must_equal "foo"
17
- end
18
-
19
- it "should not allow doctype definitions in fragments" do
20
- _(@s.fragment("<!DOCTYPE html><html>foo</html>"))
21
- .must_equal "foo"
22
-
23
- _(@s.fragment('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"><html>foo</html>'))
24
- .must_equal "foo"
25
-
26
- _(@s.fragment("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"><html>foo</html>"))
27
- .must_equal "foo"
28
- end
29
- end
30
-
31
- describe "when :allow_doctype is true" do
32
- before do
33
- @s = Sanitize.new(allow_doctype: true, elements: ["html"])
34
- end
35
-
36
- it "should allow doctype declarations in documents" do
37
- _(@s.document("<!DOCTYPE html><html>foo</html>"))
38
- .must_equal "<!DOCTYPE html><html>foo</html>"
39
-
40
- _(@s.document('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"><html>foo</html>'))
41
- .must_equal "<!DOCTYPE html><html>foo</html>"
42
-
43
- _(@s.document("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"><html>foo</html>"))
44
- .must_equal "<!DOCTYPE html><html>foo</html>"
45
- end
46
-
47
- it "should not allow obviously invalid doctype declarations in documents" do
48
- _(@s.document("<!DOCTYPE blah blah blah><html>foo</html>"))
49
- .must_equal "<!DOCTYPE html><html>foo</html>"
50
-
51
- _(@s.document("<!DOCTYPE blah><html>foo</html>"))
52
- .must_equal "<!DOCTYPE html><html>foo</html>"
53
-
54
- _(@s.document('<!DOCTYPE html BLAH "-//W3C//DTD HTML 4.01//EN"><html>foo</html>'))
55
- .must_equal "<!DOCTYPE html><html>foo</html>"
56
-
57
- _(@s.document("<!whatever><html>foo</html>"))
58
- .must_equal "<html>foo</html>"
59
- end
60
-
61
- it "should not allow doctype definitions in fragments" do
62
- _(@s.fragment("<!DOCTYPE html><html>foo</html>"))
63
- .must_equal "foo"
64
-
65
- _(@s.fragment('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"><html>foo</html>'))
66
- .must_equal "foo"
67
-
68
- _(@s.fragment("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"><html>foo</html>"))
69
- .must_equal "foo"
70
- end
71
- end
72
- end