Skip to content

Commit d79e531

Browse files
miguel perezmiguel perez
miguel perez
authored and
miguel perez
committed
add flex properties to safelist
1 parent 3e28e62 commit d79e531

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
### Unreleased
4+
5+
* Allow CSS properties `order`, `flex-direction`, `flex-grow`, `flex-wrap`, `flex-shrink`, `flex-flow`, `flex-basis`, `flex`m `justify-content`, `align-self`, `align-items`, and `align-content`. [[#190](https://github.com/flavorjones/loofah/issues/197)] (Thanks, [@miguelperez](https://github.com/miguelperez)!)
6+
37
## 2.7.0 / 2020-08-26
48

59
### Features

lib/loofah/html5/safelist.rb

+12
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,9 @@ module SafeList
549549

550550
ACCEPTABLE_CSS_PROPERTIES = Set.new([
551551
"azimuth",
552+
"align-content",
553+
"align-items",
554+
"align-self",
552555
"background-color",
553556
"border-bottom-color",
554557
"border-collapse",
@@ -562,6 +565,13 @@ module SafeList
562565
"direction",
563566
"display",
564567
"elevation",
568+
"flex",
569+
"flex-basis",
570+
"flex-direction",
571+
"flex-flow",
572+
"flex-grow",
573+
"flex-shrink",
574+
"flex-wrap",
565575
"float",
566576
"font",
567577
"font-family",
@@ -570,11 +580,13 @@ module SafeList
570580
"font-variant",
571581
"font-weight",
572582
"height",
583+
"justify-content",
573584
"letter-spacing",
574585
"line-height",
575586
"list-style",
576587
"list-style-type",
577588
"max-width",
589+
"order",
578590
"overflow",
579591
"page-break-after",
580592
"page-break-before",

test/html5/test_sanitizer.rb

+72
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,78 @@ def test_css_page_break_inside
398398
end
399399

400400

401+
def test_css_align_content
402+
html = '<div style="align-content:flex-start;"></div>'
403+
sane = Nokogiri::HTML(Loofah.scrub_fragment(html, :escape).to_xml)
404+
assert_match %r/align-content:flex-start/, sane.inner_html
405+
end
406+
407+
def test_css_align_items
408+
html = '<div style="align-items:stretch;"></div>'
409+
sane = Nokogiri::HTML(Loofah.scrub_fragment(html, :escape).to_xml)
410+
assert_match %r/align-items:stretch/, sane.inner_html
411+
end
412+
413+
def test_css_align_self
414+
html = '<div style="align-self:auto;"></div>'
415+
sane = Nokogiri::HTML(Loofah.scrub_fragment(html, :escape).to_xml)
416+
assert_match %r/align-self:auto/, sane.inner_html
417+
end
418+
419+
def test_css_flex
420+
html = '<div style="flex:none;"></div>'
421+
sane = Nokogiri::HTML(Loofah.scrub_fragment(html, :escape).to_xml)
422+
assert_match %r/flex:none/, sane.inner_html
423+
end
424+
425+
def test_css_flex_basis
426+
html = '<div style="flex-basis:auto;"></div>'
427+
sane = Nokogiri::HTML(Loofah.scrub_fragment(html, :escape).to_xml)
428+
assert_match %r/flex-basis:auto/, sane.inner_html
429+
end
430+
431+
def test_css_flex_direction
432+
html = '<div style="flex-direction:row;"></div>'
433+
sane = Nokogiri::HTML(Loofah.scrub_fragment(html, :escape).to_xml)
434+
assert_match %r/flex-direction:row/, sane.inner_html
435+
end
436+
437+
def test_css_flex_flow
438+
html = '<div style="flex-flow:column wrap;"></div>'
439+
sane = Nokogiri::HTML(Loofah.scrub_fragment(html, :escape).to_xml)
440+
assert_match %r/flex-flow:column wrap/, sane.inner_html
441+
end
442+
443+
def test_css_flex_grow
444+
html = '<div style="flex-grow:4;"></div>'
445+
sane = Nokogiri::HTML(Loofah.scrub_fragment(html, :escape).to_xml)
446+
assert_match %r/flex-grow:4/, sane.inner_html
447+
end
448+
449+
def test_css_flex_shrink
450+
html = '<div style="flex-shrink:3;"></div>'
451+
sane = Nokogiri::HTML(Loofah.scrub_fragment(html, :escape).to_xml)
452+
assert_match %r/flex-shrink:3/, sane.inner_html
453+
end
454+
455+
def test_css_flex_wrap
456+
html = '<div style="flex-wrap:wrap;"></div>'
457+
sane = Nokogiri::HTML(Loofah.scrub_fragment(html, :escape).to_xml)
458+
assert_match %r/flex-wrap:wrap/, sane.inner_html
459+
end
460+
461+
def test_css_justify_content
462+
html = '<div style="justify-content:flex-start;"></div>'
463+
sane = Nokogiri::HTML(Loofah.scrub_fragment(html, :escape).to_xml)
464+
assert_match %r/justify-content:flex-start/, sane.inner_html
465+
end
466+
467+
def test_css_order
468+
html = '<div style="order:5;"></div>'
469+
sane = Nokogiri::HTML(Loofah.scrub_fragment(html, :escape).to_xml)
470+
assert_match %r/order:5/, sane.inner_html
471+
end
472+
401473
def test_issue_90_slow_regex
402474
skip("timing tests are hard to make pass and have little regression-testing value")
403475

0 commit comments

Comments
 (0)