Skip to content

Commit 12e5ccd

Browse files
author
Juan Lulkin
committed
Merge pull request #34 from tsukasaoishi/escape-fix
Fix issue that would unescape html entities.
2 parents 7d10baa + 84756e5 commit 12e5ccd

3 files changed

Lines changed: 14 additions & 4 deletions

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/fixtures/slim-lang.slim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,15 @@ html[xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"]
130130
| render
131131
span.string
132132
| 'footer'
133-
| | Copyright © #{year} #{author}
133+
| | Copyright © #{year} #{author}
134134
p.foot.up
135135
| Source:
136136
a[href="http://github.com/slim-template/slim"]
137137
| slim-template/slim
138-
|  | Slim maintained by
138+
|  | Slim maintained by
139139
a[href="http://github.com/minad"]
140140
| minad
141-
|  | Logo & design by
141+
|  | Logo & design by
142142
a[href="http://github.com/activestylus"]
143143
| activestylus
144144
br

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_with_and_without_leading_dash '<% a = 1 %>', '- a = 1'

0 commit comments

Comments
 (0)