loofah 2.4.0 → 2.9.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of loofah might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 29f0764dd4fc0eed44139b573bd3708917cab618126b094b9faa42d26a29d949
4
- data.tar.gz: e1e9cc2ecbd68de48d1f2554a65b86bed0756616008cf9c9a7ed62af1197afa4
3
+ metadata.gz: 10f6e8ff06a760da3400cdf8660e6768cfc2e7bbcb34a3ae6aaadea5e29ff924
4
+ data.tar.gz: 7e0accdb26147612bd7da3abc8fa98a6fac850dbb7a0ee99d20375400de4b877
5
5
  SHA512:
6
- metadata.gz: 05bc54adcab4ee55e52f69685366ba81e492a6b6c25c8e282d79d4ec85349f8ac37c3e34b74ed81089bda662ebed620c208a7a46bc64f4a504ec1bf51f7c8bf9
7
- data.tar.gz: 8b0e5d75ab88d683240183b5b3e4ed3d1a1fd26bac0d89780ce64722a3d05cba95c42376208e294ad1b3b215fcb90a795e479a2d0e8a3fd643d3b136e88bb562
6
+ metadata.gz: 11b0f4dcad5a9f38444e9eebd45cb09705e536468c901c03d792711133536812f8b0579533eb54a305311d5303fdd4cf510761a9a0d42d0af46bb153d3402a3c
7
+ data.tar.gz: d6032694eaaaddd47c02868ecb037dc2673b5ebd749a7d8846c2a55e13744f9455a66b41ec16a4cf3c4905e6019df3493972ec462cd04404365ebe202e15e211
@@ -1,12 +1,59 @@
1
1
  # Changelog
2
2
 
3
+ ### 2.9.0 / 2021-01-14
4
+
5
+ * Handle CSS functions in a CSS shorthand property (like `background`). [[#199](https://github.com/flavorjones/loofah/issues/199), [#200](https://github.com/flavorjones/loofah/issues/200)]
6
+
7
+
8
+ ### 2.8.0 / 2020-11-25
9
+
10
+ * Allow CSS properties `order`, `flex-direction`, `flex-grow`, `flex-wrap`, `flex-shrink`, `flex-flow`, `flex-basis`, `flex`, `justify-content`, `align-self`, `align-items`, and `align-content`. [[#197](https://github.com/flavorjones/loofah/issues/197)] (Thanks, [@miguelperez](https://github.com/miguelperez)!)
11
+
12
+
13
+ ## 2.7.0 / 2020-08-26
14
+
15
+ ### Features
16
+
17
+ * Allow CSS properties `page-break-before`, `page-break-inside`, and `page-break-after`. [[#190](https://github.com/flavorjones/loofah/issues/190)] (Thanks, [@ahorek](https://github.com/ahorek)!)
18
+
19
+
20
+ ### Fixes
21
+
22
+ * Don't drop the `!important` rule from some CSS properties. [[#191](https://github.com/flavorjones/loofah/issues/191)] (Thanks, [@b7kich](https://github.com/b7kich)!)
23
+
24
+
25
+ ## 2.6.0 / 2020-06-16
26
+
27
+ ### Features
28
+
29
+ * Allow CSS `border-style` keywords. [[#188](https://github.com/flavorjones/loofah/issues/188)] (Thanks, [@tarcisiozf](https://github.com/tarcisiozf)!)
30
+
31
+
32
+ ## 2.5.0 / 2020-04-05
33
+
34
+ ### Features
35
+
36
+ * Allow more CSS length units: "ch", "vw", "vh", "Q", "lh", "vmin", "vmax". [[#178](https://github.com/flavorjones/loofah/issues/178)] (Thanks, [@JuanitoFatas](https://github.com/JuanitoFatas)!)
37
+
38
+
39
+ ### Fixes
40
+
41
+ * Remove comments from `Loofah::HTML::Document`s that exist outside the `html` element. [[#80](https://github.com/flavorjones/loofah/issues/80)]
42
+
43
+
44
+ ### Other changes
45
+
46
+ * Gem metadata being set [[#181](https://github.com/flavorjones/loofah/issues/181)] (Thanks, [@JuanitoFatas](https://github.com/JuanitoFatas)!)
47
+ * Test files removed from gem file [[#180](https://github.com/flavorjones/loofah/issues/180),[#166](https://github.com/flavorjones/loofah/issues/166),[#159](https://github.com/flavorjones/loofah/issues/159)] (Thanks, [@JuanitoFatas](https://github.com/JuanitoFatas) and [@greysteil](https://github.com/greysteil)!)
48
+
49
+
3
50
  ## 2.4.0 / 2019-11-25
4
51
 
5
52
  ### Features
6
53
 
7
- * Allow CSS property `max-width` [#175] (Thanks, @bchaney!)
8
- * Allow CSS sizes expressed in `rem` [#176, #177]
9
- * Add `frozen_string_literal: true` magic comment to all `lib` files. [#118]
54
+ * Allow CSS property `max-width` [[#175](https://github.com/flavorjones/loofah/issues/175)] (Thanks, [@bchaney](https://github.com/bchaney)!)
55
+ * Allow CSS sizes expressed in `rem` [[#176](https://github.com/flavorjones/loofah/issues/176), [#177](https://github.com/flavorjones/loofah/issues/177)]
56
+ * Add `frozen_string_literal: true` magic comment to all `lib` files. [[#118](https://github.com/flavorjones/loofah/issues/118)]
10
57
 
11
58
 
12
59
  ## 2.3.1 / 2019-10-22
@@ -15,24 +62,24 @@
15
62
 
16
63
  Address CVE-2019-15587: Unsanitized JavaScript may occur in sanitized output when a crafted SVG element is republished.
17
64
 
18
- This CVE's public notice is at https://github.com/flavorjones/loofah/issues/171
65
+ This CVE's public notice is at [#171](https://github.com/flavorjones/loofah/issues/171)
19
66
 
20
67
 
21
68
  ## 2.3.0 / 2019-09-28
22
69
 
23
70
  ### Features
24
71
 
25
- * Expand set of allowed protocols to include `tel:` and `line:`. [#104, #147]
26
- * Expand set of allowed CSS functions. [related to #122]
27
- * Allow greater precision in shorthand CSS values. [#149] (Thanks, @danfstucky!)
28
- * Allow CSS property `list-style` [#162] (Thanks, @jaredbeck!)
29
- * Allow CSS keywords `thick` and `thin` [#168] (Thanks, @georgeclaghorn!)
30
- * Allow HTML property `contenteditable` [#167] (Thanks, @andreynering!)
72
+ * Expand set of allowed protocols to include `tel:` and `line:`. [[#104](https://github.com/flavorjones/loofah/issues/104), [#147](https://github.com/flavorjones/loofah/issues/147)]
73
+ * Expand set of allowed CSS functions. [related to [#122](https://github.com/flavorjones/loofah/issues/122)]
74
+ * Allow greater precision in shorthand CSS values. [[#149](https://github.com/flavorjones/loofah/issues/149)] (Thanks, [@danfstucky](https://github.com/danfstucky)!)
75
+ * Allow CSS property `list-style` [[#162](https://github.com/flavorjones/loofah/issues/162)] (Thanks, [@jaredbeck](https://github.com/jaredbeck)!)
76
+ * Allow CSS keywords `thick` and `thin` [[#168](https://github.com/flavorjones/loofah/issues/168)] (Thanks, [@georgeclaghorn](https://github.com/georgeclaghorn)!)
77
+ * Allow HTML property `contenteditable` [[#167](https://github.com/flavorjones/loofah/issues/167)] (Thanks, [@andreynering](https://github.com/andreynering)!)
31
78
 
32
79
 
33
80
  ### Bug fixes
34
81
 
35
- * CSS hex values are no longer limited to lowercase hex. Previously uppercase hex were scrubbed. [#165] (Thanks, @asok!)
82
+ * CSS hex values are no longer limited to lowercase hex. Previously uppercase hex were scrubbed. [[#165](https://github.com/flavorjones/loofah/issues/165)] (Thanks, [@asok](https://github.com/asok)!)
36
83
 
37
84
 
38
85
  ### Deprecations / Name Changes
@@ -43,7 +90,7 @@ The following method and constants are hereby deprecated, and will be completely
43
90
  * Deprecate `Loofah::Helpers::ActionView::WhiteListSanitizer`, please use `Loofah::Helpers::ActionView::SafeListSanitizer` instead.
44
91
  * Deprecate `Loofah::HTML5::WhiteList`, please use `Loofah::HTML5::SafeList` instead.
45
92
 
46
- Thanks to @JuanitoFatas for submitting these changes in #164 and for making the language used in Loofah more inclusive.
93
+ Thanks to [@JuanitoFatas](https://github.com/JuanitoFatas) for submitting these changes in [#164](https://github.com/flavorjones/loofah/issues/164) and for making the language used in Loofah more inclusive.
47
94
 
48
95
 
49
96
  ## 2.2.3 / 2018-10-30
@@ -52,7 +99,7 @@ Thanks to @JuanitoFatas for submitting these changes in #164 and for making the
52
99
 
53
100
  Address CVE-2018-16468: Unsanitized JavaScript may occur in sanitized output when a crafted SVG element is republished.
54
101
 
55
- This CVE's public notice is at https://github.com/flavorjones/loofah/issues/154
102
+ This CVE's public notice is at [#154](https://github.com/flavorjones/loofah/issues/154)
56
103
 
57
104
 
58
105
  ## Meta / 2018-10-27
@@ -79,76 +126,76 @@ attribute scrubbers should they need to address CVE-2018-8048.
79
126
 
80
127
  Addresses CVE-2018-8048. Loofah allowed non-whitelisted attributes to be present in sanitized output when input with specially-crafted HTML fragments.
81
128
 
82
- This CVE's public notice is at https://github.com/flavorjones/loofah/issues/144
129
+ This CVE's public notice is at [#144](https://github.com/flavorjones/loofah/issues/144)
83
130
 
84
131
 
85
132
  ## 2.2.0 / 2018-02-11
86
133
 
87
134
  ### Features:
88
135
 
89
- * Support HTML5 `<main>` tag. #133 (Thanks, @MothOnMars!)
90
- * Recognize HTML5 block elements. #136 (Thanks, @MothOnMars!)
91
- * Support SVG `<symbol>` tag. #131 (Thanks, @baopham!)
92
- * Support for whitelisting CSS functions, initially just `calc` and `rgb`. #122/#123/#129 (Thanks, @NikoRoberts!)
93
- * Whitelist CSS property `list-style-type`. #68/#137/#142 (Thanks, @andela-ysanni and @NikoRoberts!)
136
+ * Support HTML5 `<main>` tag. [#133](https://github.com/flavorjones/loofah/issues/133) (Thanks, [@MothOnMars](https://github.com/MothOnMars)!)
137
+ * Recognize HTML5 block elements. [#136](https://github.com/flavorjones/loofah/issues/136) (Thanks, [@MothOnMars](https://github.com/MothOnMars)!)
138
+ * Support SVG `<symbol>` tag. [#131](https://github.com/flavorjones/loofah/issues/131) (Thanks, [@baopham](https://github.com/baopham)!)
139
+ * Support for whitelisting CSS functions, initially just `calc` and `rgb`. [#122](https://github.com/flavorjones/loofah/issues/122)/[#123](https://github.com/flavorjones/loofah/issues/123)/[#129](https://github.com/flavorjones/loofah/issues/129) (Thanks, [@NikoRoberts](https://github.com/NikoRoberts)!)
140
+ * Whitelist CSS property `list-style-type`. [#68](https://github.com/flavorjones/loofah/issues/68)/[#137](https://github.com/flavorjones/loofah/issues/137)/[#142](https://github.com/flavorjones/loofah/issues/142) (Thanks, [@andela-ysanni](https://github.com/andela-ysanni) and [@NikoRoberts](https://github.com/NikoRoberts)!)
94
141
 
95
142
  ### Bugfixes:
96
143
 
97
- * Properly handle nested `script` tags. #127.
144
+ * Properly handle nested `script` tags. [#127](https://github.com/flavorjones/loofah/issues/127).
98
145
 
99
146
 
100
147
  ## 2.1.1 / 2017-09-24
101
148
 
102
149
  ### Bugfixes:
103
150
 
104
- * Removed warning for unused variable. #124 (Thanks, @y-yagi!)
151
+ * Removed warning for unused variable. [#124](https://github.com/flavorjones/loofah/issues/124) (Thanks, [@y-yagi](https://github.com/y-yagi)!)
105
152
 
106
153
 
107
154
  ## 2.1.0 / 2017-09-24
108
155
 
109
156
  ### Notes:
110
157
 
111
- * Re-implemented CSS parsing and sanitization using the [crass](https://github.com/rgrove/crass) library. #91
158
+ * Re-implemented CSS parsing and sanitization using the [crass](https://github.com/rgrove/crass) library. [#91](https://github.com/flavorjones/loofah/issues/91)
112
159
 
113
160
 
114
161
  ### Features:
115
162
 
116
- * Added :noopener HTML scrubber (Thanks, @tastycode!)
117
- * Support `data` URIs with the following media types: text/plain, text/css, image/png, image/gif, image/jpeg, image/svg+xml. #101, #120. (Thanks, @mrpasquini!)
163
+ * Added :noopener HTML scrubber (Thanks, [@tastycode](https://github.com/tastycode)!)
164
+ * Support `data` URIs with the following media types: text/plain, text/css, image/png, image/gif, image/jpeg, image/svg+xml. [#101](https://github.com/flavorjones/loofah/issues/101), [#120](https://github.com/flavorjones/loofah/issues/120). (Thanks, [@mrpasquini](https://github.com/mrpasquini)!)
118
165
 
119
166
 
120
167
  ### Bugfixes:
121
168
 
122
- * The :unprintable scrubber now scrubs unprintable characters in CDATA nodes (like `<script>`). #124
123
- * Allow negative values in CSS properties. Restores functionality that was reverted in v2.0.3. #91
169
+ * The :unprintable scrubber now scrubs unprintable characters in CDATA nodes (like `<script>`). [#124](https://github.com/flavorjones/loofah/issues/124)
170
+ * Allow negative values in CSS properties. Restores functionality that was reverted in v2.0.3. [#91](https://github.com/flavorjones/loofah/issues/91)
124
171
 
125
172
 
126
173
  ## 2.0.3 / 2015-08-17
127
174
 
128
175
  ### Bug fixes:
129
176
 
130
- * Revert support for negative values in CSS properties due to slow performance. #90 (Related to #85.)
177
+ * Revert support for negative values in CSS properties due to slow performance. [#90](https://github.com/flavorjones/loofah/issues/90) (Related to [#85](https://github.com/flavorjones/loofah/issues/85).)
131
178
 
132
179
 
133
180
  ## 2.0.2 / 2015-05-05
134
181
 
135
182
  ### Bug fixes:
136
183
 
137
- * Fix error with `#to_text` when Loofah::Helpers hadn't been required. #75
138
- * Allow multi-word data attributes. #84 (Thanks, @jstorimer!)
139
- * Allow negative values in CSS properties. #85 (Thanks, @siddhartham!)
184
+ * Fix error with `#to_text` when Loofah::Helpers hadn't been required. [#75](https://github.com/flavorjones/loofah/issues/75)
185
+ * Allow multi-word data attributes. [#84](https://github.com/flavorjones/loofah/issues/84) (Thanks, [@jstorimer](https://github.com/jstorimer)!)
186
+ * Allow negative values in CSS properties. [#85](https://github.com/flavorjones/loofah/issues/85) (Thanks, [@siddhartham](https://github.com/siddhartham)!)
140
187
 
141
188
 
142
189
  ## 2.0.1 / 2014-08-21
143
190
 
144
191
  ### Bug fixes:
145
192
 
146
- * Load RR correctly when running test files directly. (Thanks, @ktdreyer!)
193
+ * Load RR correctly when running test files directly. (Thanks, [@ktdreyer](https://github.com/ktdreyer)!)
147
194
 
148
195
 
149
196
  ### Notes:
150
197
 
151
- * Extracted HTML5::Scrub#scrub_css_attribute to accommodate the Rails integration work. (Thanks, @kaspth!)
198
+ * Extracted HTML5::Scrub#scrub_css_attribute to accommodate the Rails integration work. (Thanks, [@kaspth](https://github.com/kaspth)!)
152
199
 
153
200
 
154
201
  ## 2.0.0 / 2014-05-09
@@ -164,19 +211,19 @@ This CVE's public notice is at https://github.com/flavorjones/loofah/issues/144
164
211
  * tags: `article`, `aside`, `bdi`, `bdo`, `canvas`, `command`, `datalist`, `details`, `figcaption`, `figure`, `footer`, `header`, `mark`, `meter`, `nav`, `output`, `section`, `summary`, `time`
165
212
  * attributes: `data-*` (Thanks, Rafael Franca!)
166
213
  * URI attributes: `poster` and `preload`
167
- * Addition of the `:unprintable` scrubber to remove unprintable characters from text nodes. #65 (Thanks, Matt Swanson!)
168
- * `Loofah.fragment` accepts an optional encoding argument, compatible with `Nokogiri::HTML::DocumentFragment.parse`. #62 (Thanks, Ben Atkins!)
214
+ * Addition of the `:unprintable` scrubber to remove unprintable characters from text nodes. [#65](https://github.com/flavorjones/loofah/issues/65) (Thanks, Matt Swanson!)
215
+ * `Loofah.fragment` accepts an optional encoding argument, compatible with `Nokogiri::HTML::DocumentFragment.parse`. [#62](https://github.com/flavorjones/loofah/issues/62) (Thanks, Ben Atkins!)
169
216
  * HTML5 sanitizers now remove attributes without values. (Thanks, Kasper Timm Hansen!)
170
217
 
171
218
  ### Bug fixes:
172
219
 
173
220
  * HTML5 sanitizers' CSS keyword check now actually works (broken in v2.0). Additional regression tests added. (Thanks, Kasper Timm Hansen!)
174
- * HTML5 sanitizers now allow negative arguments to CSS. #64 (Thanks, Jon Calhoun!)
221
+ * HTML5 sanitizers now allow negative arguments to CSS. [#64](https://github.com/flavorjones/loofah/issues/64) (Thanks, Jon Calhoun!)
175
222
 
176
223
 
177
224
  ## 1.2.1 (2012-04-14)
178
225
 
179
- * Declaring encoding in html5/scrub.rb. Without this, use of the ruby -KU option would cause havoc. (#32)
226
+ * Declaring encoding in html5/scrub.rb. Without this, use of the ruby -KU option would cause havoc. ([#32](https://github.com/flavorjones/loofah/issues/32))
180
227
 
181
228
 
182
229
  ## 1.2.0 (2011-08-08)
@@ -194,7 +241,7 @@ This CVE's public notice is at https://github.com/flavorjones/loofah/issues/144
194
241
  * Additional HTML5lib whitelist elements (from html5lib 1524:80b5efe26230).
195
242
  Up to date with HTML5lib ruby code as of 1723:7ee6a0331856.
196
243
  * Whitelists (which are not part of the public API) are now Sets (were previously Arrays).
197
- * Don't explode when encountering UTF-8 URIs. (#25, #29)
244
+ * Don't explode when encountering UTF-8 URIs. ([#25](https://github.com/flavorjones/loofah/issues/25), [#29](https://github.com/flavorjones/loofah/issues/29))
198
245
 
199
246
 
200
247
  ## 1.0.0 (2010-10-26)
@@ -212,7 +259,7 @@ This CVE's public notice is at https://github.com/flavorjones/loofah/issues/144
212
259
  * New methods Loofah::HTML::Document#to_text and
213
260
  Loofah::HTML::DocumentFragment#to_text do the right thing with
214
261
  whitespace. Note that these methods are significantly slower than
215
- #text. GH #12
262
+ #text. GH [#12](https://github.com/flavorjones/loofah/issues/12)
216
263
  * Loofah::Elements::BLOCK_LEVEL contains a canonical list of HTML4 block-level4 elements.
217
264
  * Loofah::HTML::Document#text and Loofah::HTML::DocumentFragment#text
218
265
  will return unescaped HTML entities by passing :encode_special_chars => false.
@@ -226,7 +273,7 @@ This CVE's public notice is at https://github.com/flavorjones/loofah/issues/144
226
273
 
227
274
  ### Bug fixes:
228
275
 
229
- * Loofah::XssFoliate was not properly escaping HTML entities when implicitly scrubbing a string attribute. GH #17
276
+ * Loofah::XssFoliate was not properly escaping HTML entities when implicitly scrubbing a string attribute. GH [#17](https://github.com/flavorjones/loofah/issues/17)
230
277
 
231
278
 
232
279
  ## 0.4.3 (2010-01-29)
@@ -254,7 +301,7 @@ This CVE's public notice is at https://github.com/flavorjones/loofah/issues/144
254
301
 
255
302
  ### Bug fixes:
256
303
 
257
- * Supporting Rails apps that aren't loading ActiveRecord. GH #10
304
+ * Supporting Rails apps that aren't loading ActiveRecord. GH [#10](https://github.com/flavorjones/loofah/issues/10)
258
305
 
259
306
  ### Miscellaneous:
260
307
 
@@ -315,13 +362,13 @@ This CVE's public notice is at https://github.com/flavorjones/loofah/issues/144
315
362
  ### Enhancements:
316
363
 
317
364
  * when loaded in a Rails app, automatically extend ActiveRecord::Base
318
- with html_fragment and html_document. GH #6 (Thanks Josh Nichols!)
365
+ with html_fragment and html_document. GH [#6](https://github.com/flavorjones/loofah/issues/6) (Thanks Josh Nichols!)
319
366
 
320
367
  ### Bugfixes:
321
368
 
322
369
  * ActiveRecord scrubbing should generate strings instead of Document or
323
- DocumentFragment objects. GH #5
324
- * init.rb fixed to support installation as a Rails plugin. GH #6
370
+ DocumentFragment objects. GH [#5](https://github.com/flavorjones/loofah/issues/5)
371
+ * init.rb fixed to support installation as a Rails plugin. GH [#6](https://github.com/flavorjones/loofah/issues/6)
325
372
  (Thanks Josh Nichols!)
326
373
 
327
374
 
data/README.md CHANGED
@@ -6,10 +6,9 @@
6
6
 
7
7
  ## Status
8
8
 
9
- |System|Status|
10
- |--|--|
11
- | Concourse CI | [![Concourse CI](https://ci.nokogiri.org/api/v1/teams/nokogiri-core/pipelines/loofah/jobs/ruby-2.5/badge)](https://ci.nokogiri.org/teams/nokogiri-core/pipelines/loofah?groups=master) |
12
- | Code Climate | [![Code Climate](https://codeclimate.com/github/flavorjones/loofah.svg)](https://codeclimate.com/github/flavorjones/loofah) |
9
+ [![Concourse CI](https://ci.nokogiri.org/api/v1/teams/nokogiri-core/pipelines/loofah/jobs/ruby-2.5/badge)](https://ci.nokogiri.org/teams/nokogiri-core/pipelines/loofah?groups=master)
10
+ [![Code Climate](https://codeclimate.com/github/flavorjones/loofah.svg)](https://codeclimate.com/github/flavorjones/loofah)
11
+ [![Tidelift dependencies](https://tidelift.com/badges/package/rubygems/loofah)](https://tidelift.com/subscription/pkg/rubygems-loofah?utm_source=rubygems-loofah&utm_medium=referral&utm_campaign=readme)
13
12
 
14
13
 
15
14
  ## Description
@@ -301,6 +300,10 @@ And the mailing list is on Google Groups:
301
300
 
302
301
  And the IRC channel is \#loofah on freenode.
303
302
 
303
+ Consider subscribing to [Tidelift][tidelift] which provides license assurances and timely security notifications for your open source dependencies, including Loofah. [Tidelift][tidelift] subscriptions also help the Loofah maintainers fund our [automated testing](https://ci.nokogiri.org) which in turn allows us to ship releases, bugfixes, and security updates more often.
304
+
305
+ [tidelift]: https://tidelift.com/subscription/pkg/rubygems-loofah?utm_source=undefined&utm_medium=referral&utm_campaign=enterprise
306
+
304
307
 
305
308
  ## Security
306
309
 
@@ -3,21 +3,22 @@ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__))) unless $LOAD_PATH.i
3
3
 
4
4
  require "nokogiri"
5
5
 
6
- require "loofah/metahelpers"
7
- require "loofah/elements"
6
+ require_relative "loofah/version"
7
+ require_relative "loofah/metahelpers"
8
+ require_relative "loofah/elements"
8
9
 
9
- require "loofah/html5/safelist"
10
- require "loofah/html5/libxml2_workarounds"
11
- require "loofah/html5/scrub"
10
+ require_relative "loofah/html5/safelist"
11
+ require_relative "loofah/html5/libxml2_workarounds"
12
+ require_relative "loofah/html5/scrub"
12
13
 
13
- require "loofah/scrubber"
14
- require "loofah/scrubbers"
14
+ require_relative "loofah/scrubber"
15
+ require_relative "loofah/scrubbers"
15
16
 
16
- require "loofah/instance_methods"
17
- require "loofah/xml/document"
18
- require "loofah/xml/document_fragment"
19
- require "loofah/html/document"
20
- require "loofah/html/document_fragment"
17
+ require_relative "loofah/instance_methods"
18
+ require_relative "loofah/xml/document"
19
+ require_relative "loofah/xml/document_fragment"
20
+ require_relative "loofah/html/document"
21
+ require_relative "loofah/html/document_fragment"
21
22
 
22
23
  # == Strings and IO Objects as Input
23
24
  #
@@ -28,14 +29,11 @@ require "loofah/html/document_fragment"
28
29
  # quantities of docs.
29
30
  #
30
31
  module Loofah
31
- # The version of Loofah you are using
32
- VERSION = "2.4.0"
33
-
34
32
  class << self
35
33
  # Shortcut for Loofah::HTML::Document.parse
36
34
  # This method accepts the same parameters as Nokogiri::HTML::Document.parse
37
35
  def document(*args, &block)
38
- Loofah::HTML::Document.parse(*args, &block)
36
+ remove_comments_before_html_element Loofah::HTML::Document.parse(*args, &block)
39
37
  end
40
38
 
41
39
  # Shortcut for Loofah::HTML::DocumentFragment.parse
@@ -80,5 +78,23 @@ module Loofah
80
78
  def remove_extraneous_whitespace(string)
81
79
  string.gsub(/\n\s*\n\s*\n/, "\n\n")
82
80
  end
81
+
82
+ private
83
+
84
+ # remove comments that exist outside of the HTML element.
85
+ #
86
+ # these comments are allowed by the HTML spec:
87
+ #
88
+ # https://www.w3.org/TR/html401/struct/global.html#h-7.1
89
+ #
90
+ # but are not scrubbed by Loofah because these nodes don't meet
91
+ # the contract that scrubbers expect of a node (e.g., it can be
92
+ # replaced, sibling and children nodes can be created).
93
+ def remove_comments_before_html_element(doc)
94
+ doc.children.each do |child|
95
+ child.unlink if child.comment?
96
+ end
97
+ doc
98
+ end
83
99
  end
84
100
  end
@@ -1,90 +1,90 @@
1
1
  # frozen_string_literal: true
2
- require 'set'
2
+ require "set"
3
3
 
4
4
  module Loofah
5
5
  module Elements
6
6
  STRICT_BLOCK_LEVEL_HTML4 = Set.new %w[
7
- address
8
- blockquote
9
- center
10
- dir
11
- div
12
- dl
13
- fieldset
14
- form
15
- h1
16
- h2
17
- h3
18
- h4
19
- h5
20
- h6
21
- hr
22
- isindex
23
- menu
24
- noframes
25
- noscript
26
- ol
27
- p
28
- pre
29
- table
30
- ul
31
- ]
7
+ address
8
+ blockquote
9
+ center
10
+ dir
11
+ div
12
+ dl
13
+ fieldset
14
+ form
15
+ h1
16
+ h2
17
+ h3
18
+ h4
19
+ h5
20
+ h6
21
+ hr
22
+ isindex
23
+ menu
24
+ noframes
25
+ noscript
26
+ ol
27
+ p
28
+ pre
29
+ table
30
+ ul
31
+ ]
32
32
 
33
33
  # https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements
34
34
  STRICT_BLOCK_LEVEL_HTML5 = Set.new %w[
35
- address
36
- article
37
- aside
38
- blockquote
39
- canvas
40
- dd
41
- div
42
- dl
43
- dt
44
- fieldset
45
- figcaption
46
- figure
47
- footer
48
- form
49
- h1
50
- h2
51
- h3
52
- h4
53
- h5
54
- h6
55
- header
56
- hgroup
57
- hr
58
- li
59
- main
60
- nav
61
- noscript
62
- ol
63
- output
64
- p
65
- pre
66
- section
67
- table
68
- tfoot
69
- ul
70
- video
71
- ]
35
+ address
36
+ article
37
+ aside
38
+ blockquote
39
+ canvas
40
+ dd
41
+ div
42
+ dl
43
+ dt
44
+ fieldset
45
+ figcaption
46
+ figure
47
+ footer
48
+ form
49
+ h1
50
+ h2
51
+ h3
52
+ h4
53
+ h5
54
+ h6
55
+ header
56
+ hgroup
57
+ hr
58
+ li
59
+ main
60
+ nav
61
+ noscript
62
+ ol
63
+ output
64
+ p
65
+ pre
66
+ section
67
+ table
68
+ tfoot
69
+ ul
70
+ video
71
+ ]
72
72
 
73
73
  STRICT_BLOCK_LEVEL = STRICT_BLOCK_LEVEL_HTML4 + STRICT_BLOCK_LEVEL_HTML5
74
74
 
75
75
  # The following elements may also be considered block-level
76
76
  # elements since they may contain block-level elements
77
77
  LOOSE_BLOCK_LEVEL = Set.new %w[dd
78
- dt
79
- frameset
80
- li
81
- tbody
82
- td
83
- tfoot
84
- th
85
- thead
86
- tr
87
- ]
78
+ dt
79
+ frameset
80
+ li
81
+ tbody
82
+ td
83
+ tfoot
84
+ th
85
+ thead
86
+ tr
87
+ ]
88
88
 
89
89
  BLOCK_LEVEL = STRICT_BLOCK_LEVEL + LOOSE_BLOCK_LEVEL
90
90
  end