@@ -12,12 +12,12 @@ def test_sanitizer_sanitize_raises_not_implemented_error
12
12
end
13
13
14
14
def test_sanitize_nested_script
15
- sanitizer = Rails ::Html ::WhiteListSanitizer . new
15
+ sanitizer = Rails ::Html ::SafeListSanitizer . new
16
16
assert_equal '<script>alert("XSS");</script>' , sanitizer . sanitize ( '<script><script></script>alert("XSS");<script><</script>/</script><script>script></script>' , tags : %w( em ) )
17
17
end
18
18
19
19
def test_sanitize_nested_script_in_style
20
- sanitizer = Rails ::Html ::WhiteListSanitizer . new
20
+ sanitizer = Rails ::Html ::SafeListSanitizer . new
21
21
assert_equal '<script>alert("XSS");</script>' , sanitizer . sanitize ( '<style><script></style>alert("XSS");<style><</style>/</style><style>script></style>' , tags : %w( em ) )
22
22
end
23
23
@@ -255,38 +255,38 @@ def test_custom_attributes_overrides_allowed_attributes
255
255
256
256
def test_should_allow_custom_tags
257
257
text = "<u>foo</u>"
258
- assert_equal text , white_list_sanitize ( text , tags : %w( u ) )
258
+ assert_equal text , safe_list_sanitize ( text , tags : %w( u ) )
259
259
end
260
260
261
261
def test_should_allow_only_custom_tags
262
262
text = "<u>foo</u> with <i>bar</i>"
263
- assert_equal "<u>foo</u> with bar" , white_list_sanitize ( text , tags : %w( u ) )
263
+ assert_equal "<u>foo</u> with bar" , safe_list_sanitize ( text , tags : %w( u ) )
264
264
end
265
265
266
266
def test_should_allow_custom_tags_with_attributes
267
267
text = %(<blockquote cite="http://example.com/">foo</blockquote>)
268
- assert_equal text , white_list_sanitize ( text )
268
+ assert_equal text , safe_list_sanitize ( text )
269
269
end
270
270
271
271
def test_should_allow_custom_tags_with_custom_attributes
272
272
text = %(<blockquote foo="bar">Lorem ipsum</blockquote>)
273
- assert_equal text , white_list_sanitize ( text , attributes : [ 'foo' ] )
273
+ assert_equal text , safe_list_sanitize ( text , attributes : [ 'foo' ] )
274
274
end
275
275
276
276
def test_scrub_style_if_style_attribute_option_is_passed
277
277
input = '<p style="color: #000; background-image: url(http://www.ragingplatypus.com/i/cam-full.jpg);"></p>'
278
- assert_equal '<p style="color: #000;"></p>' , white_list_sanitize ( input , attributes : %w( style ) )
278
+ assert_equal '<p style="color: #000;"></p>' , safe_list_sanitize ( input , attributes : %w( style ) )
279
279
end
280
280
281
281
def test_should_raise_argument_error_if_tags_is_not_enumerable
282
282
assert_raises ArgumentError do
283
- white_list_sanitize ( '<a>some html</a>' , tags : 'foo' )
283
+ safe_list_sanitize ( '<a>some html</a>' , tags : 'foo' )
284
284
end
285
285
end
286
286
287
287
def test_should_raise_argument_error_if_attributes_is_not_enumerable
288
288
assert_raises ArgumentError do
289
- white_list_sanitize ( '<a>some html</a>' , attributes : 'foo' )
289
+ safe_list_sanitize ( '<a>some html</a>' , attributes : 'foo' )
290
290
end
291
291
end
292
292
@@ -295,7 +295,7 @@ def test_should_not_accept_non_loofah_inheriting_scrubber
295
295
def scrubber . scrub ( node ) ; node . name = 'h1' ; end
296
296
297
297
assert_raises Loofah ::ScrubberNotFound do
298
- white_list_sanitize ( '<a>some html</a>' , scrubber : scrubber )
298
+ safe_list_sanitize ( '<a>some html</a>' , scrubber : scrubber )
299
299
end
300
300
end
301
301
@@ -304,19 +304,19 @@ def test_should_accept_loofah_inheriting_scrubber
304
304
def scrubber . scrub ( node ) ; node . name = 'h1' ; end
305
305
306
306
html = "<script>hello!</script>"
307
- assert_equal "<h1>hello!</h1>" , white_list_sanitize ( html , scrubber : scrubber )
307
+ assert_equal "<h1>hello!</h1>" , safe_list_sanitize ( html , scrubber : scrubber )
308
308
end
309
309
310
310
def test_should_accept_loofah_scrubber_that_wraps_a_block
311
311
scrubber = Loofah ::Scrubber . new { |node | node . name = 'h1' }
312
312
html = "<script>hello!</script>"
313
- assert_equal "<h1>hello!</h1>" , white_list_sanitize ( html , scrubber : scrubber )
313
+ assert_equal "<h1>hello!</h1>" , safe_list_sanitize ( html , scrubber : scrubber )
314
314
end
315
315
316
316
def test_custom_scrubber_takes_precedence_over_other_options
317
317
scrubber = Loofah ::Scrubber . new { |node | node . name = 'h1' }
318
318
html = "<script>hello!</script>"
319
- assert_equal "<h1>hello!</h1>" , white_list_sanitize ( html , scrubber : scrubber , tags : [ 'foo' ] )
319
+ assert_equal "<h1>hello!</h1>" , safe_list_sanitize ( html , scrubber : scrubber , tags : [ 'foo' ] )
320
320
end
321
321
322
322
[ %w( img src ) , %w( a href ) ] . each do |( tag , attr ) |
@@ -468,7 +468,7 @@ def test_x03a_legitimate
468
468
end
469
469
470
470
def test_sanitize_ascii_8bit_string
471
- white_list_sanitize ( '<a>hello</a>' . encode ( 'ASCII-8BIT' ) ) . tap do |sanitized |
471
+ safe_list_sanitize ( '<a>hello</a>' . encode ( 'ASCII-8BIT' ) ) . tap do |sanitized |
472
472
assert_equal '<a>hello</a>' , sanitized
473
473
assert_equal Encoding ::UTF_8 , sanitized . encoding
474
474
end
@@ -481,45 +481,45 @@ def test_sanitize_data_attributes
481
481
482
482
def test_allow_data_attribute_if_requested
483
483
text = %(<a data-foo="foo">foo</a>)
484
- assert_equal %(<a data-foo="foo">foo</a>) , white_list_sanitize ( text , attributes : [ 'data-foo' ] )
484
+ assert_equal %(<a data-foo="foo">foo</a>) , safe_list_sanitize ( text , attributes : [ 'data-foo' ] )
485
485
end
486
486
487
- def test_uri_escaping_of_href_attr_in_a_tag_in_white_list_sanitizer
487
+ def test_uri_escaping_of_href_attr_in_a_tag_in_safe_list_sanitizer
488
488
skip if RUBY_VERSION < "2.3"
489
489
490
490
html = %{<a href='examp<!--" unsafeattr=foo()>-->le.com'>test</a>}
491
491
492
- text = white_list_sanitize ( html )
492
+ text = safe_list_sanitize ( html )
493
493
494
494
assert_equal %{<a href=\" examp<!--%22%20unsafeattr=foo()>-->le.com\" >test</a>} , text
495
495
end
496
496
497
- def test_uri_escaping_of_src_attr_in_a_tag_in_white_list_sanitizer
497
+ def test_uri_escaping_of_src_attr_in_a_tag_in_safe_list_sanitizer
498
498
skip if RUBY_VERSION < "2.3"
499
499
500
500
html = %{<a src='examp<!--" unsafeattr=foo()>-->le.com'>test</a>}
501
501
502
- text = white_list_sanitize ( html )
502
+ text = safe_list_sanitize ( html )
503
503
504
504
assert_equal %{<a src=\" examp<!--%22%20unsafeattr=foo()>-->le.com\" >test</a>} , text
505
505
end
506
506
507
- def test_uri_escaping_of_name_attr_in_a_tag_in_white_list_sanitizer
507
+ def test_uri_escaping_of_name_attr_in_a_tag_in_safe_list_sanitizer
508
508
skip if RUBY_VERSION < "2.3"
509
509
510
510
html = %{<a name='examp<!--" unsafeattr=foo()>-->le.com'>test</a>}
511
511
512
- text = white_list_sanitize ( html )
512
+ text = safe_list_sanitize ( html )
513
513
514
514
assert_equal %{<a name=\" examp<!--%22%20unsafeattr=foo()>-->le.com\" >test</a>} , text
515
515
end
516
516
517
- def test_uri_escaping_of_name_action_in_a_tag_in_white_list_sanitizer
517
+ def test_uri_escaping_of_name_action_in_a_tag_in_safe_list_sanitizer
518
518
skip if RUBY_VERSION < "2.3"
519
519
520
520
html = %{<a action='examp<!--" unsafeattr=foo()>-->le.com'>test</a>}
521
521
522
- text = white_list_sanitize ( html , attributes : [ 'action' ] )
522
+ text = safe_list_sanitize ( html , attributes : [ 'action' ] )
523
523
524
524
assert_equal %{<a action=\" examp<!--%22%20unsafeattr=foo()>-->le.com\" >test</a>} , text
525
525
end
@@ -538,35 +538,35 @@ def link_sanitize(input, options = {})
538
538
Rails ::Html ::LinkSanitizer . new . sanitize ( input , options )
539
539
end
540
540
541
- def white_list_sanitize ( input , options = { } )
542
- Rails ::Html ::WhiteListSanitizer . new . sanitize ( input , options )
541
+ def safe_list_sanitize ( input , options = { } )
542
+ Rails ::Html ::SafeListSanitizer . new . sanitize ( input , options )
543
543
end
544
544
545
545
def assert_sanitized ( input , expected = nil )
546
546
if input
547
- assert_dom_equal expected || input , white_list_sanitize ( input )
547
+ assert_dom_equal expected || input , safe_list_sanitize ( input )
548
548
else
549
- assert_nil white_list_sanitize ( input )
549
+ assert_nil safe_list_sanitize ( input )
550
550
end
551
551
end
552
552
553
553
def sanitize_css ( input )
554
- Rails ::Html ::WhiteListSanitizer . new . sanitize_css ( input )
554
+ Rails ::Html ::SafeListSanitizer . new . sanitize_css ( input )
555
555
end
556
556
557
557
def scope_allowed_tags ( tags )
558
- old_tags = Rails ::Html ::WhiteListSanitizer . allowed_tags
559
- Rails ::Html ::WhiteListSanitizer . allowed_tags = tags
560
- yield Rails ::Html ::WhiteListSanitizer . new
558
+ old_tags = Rails ::Html ::SafeListSanitizer . allowed_tags
559
+ Rails ::Html ::SafeListSanitizer . allowed_tags = tags
560
+ yield Rails ::Html ::SafeListSanitizer . new
561
561
ensure
562
- Rails ::Html ::WhiteListSanitizer . allowed_tags = old_tags
562
+ Rails ::Html ::SafeListSanitizer . allowed_tags = old_tags
563
563
end
564
564
565
565
def scope_allowed_attributes ( attributes )
566
- old_attributes = Rails ::Html ::WhiteListSanitizer . allowed_attributes
567
- Rails ::Html ::WhiteListSanitizer . allowed_attributes = attributes
568
- yield Rails ::Html ::WhiteListSanitizer . new
566
+ old_attributes = Rails ::Html ::SafeListSanitizer . allowed_attributes
567
+ Rails ::Html ::SafeListSanitizer . allowed_attributes = attributes
568
+ yield Rails ::Html ::SafeListSanitizer . new
569
569
ensure
570
- Rails ::Html ::WhiteListSanitizer . allowed_attributes = old_attributes
570
+ Rails ::Html ::SafeListSanitizer . allowed_attributes = old_attributes
571
571
end
572
572
end
0 commit comments