Skip to content

Commit ba3cb96

Browse files
committed
don't unescape html
1 parent c2a15a4 commit ba3cb96

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

lib/html2slim/hpricot_monkeypatches.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ def to_slim(lvl=0)
2020
end
2121

2222
class Hpricot::Text
23-
include SlimText
23+
def to_slim(lvl=0)
24+
str = content.to_s
25+
return nil if str.strip.empty?
26+
(' ' * lvl) + %(| #{str.gsub(/\s+/, ' ')})
27+
end
2428
end
2529

2630
class Hpricot::Comment

test/test_html2slim.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ def test_data_attributes
8484
assert_html_to_slim html, slim
8585
end
8686

87+
def test_escaped_text
88+
text = "this is js code sample.  » <script>alert(0)</script>"
89+
assert_html_to_slim text, "| #{text}"
90+
assert_erb_to_slim text, "| #{text}"
91+
end
92+
8793
def test_erb_tags
8894
# simple
8995
assert_erb_to_slim '<% a = 1 %>', '- a = 1'

0 commit comments

Comments
 (0)