1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

Merge pull request #124 from southwolf/master

Fix #117 Identify and remove UTF-8 BOM
This commit is contained in:
Takashi Kokubun 2018-09-05 22:49:50 +09:00 committed by GitHub
commit f3b2ca758e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 5 deletions

View file

@ -98,7 +98,12 @@ module Hamlit
@template_index = 0
@template_tabs = 0
match = template.rstrip.scan(/(([ \t]+)?(.*?))(?:\Z|\r\n|\r|\n)/m)
# try to check encoding and clean UTF-8 BOM
template_bom_stripped = check_haml_encoding(template) do |msg, line|
raise Hamlit::Error.new(msg, line)
end
match = template_bom_stripped.rstrip.scan(/(([ \t]+)?(.*?))(?:\Z|\r\n|\r|\n)/m)
# discard the last match which is always blank
match.pop
@template = match.each_with_index.map do |(full, whitespace, text), index|

View file

@ -1955,10 +1955,10 @@ HAML
# Encodings
def test_utf_8_bom; skip # encoding
def test_utf_8_bom; # encoding
assert_equal <<HTML, render(<<HAML)
<div class='foo'>
<p>baz</p>
<p>baz</p>
</div>
HTML
\xEF\xBB\xBF.foo
@ -1999,10 +1999,10 @@ HAML
end
end
def test_encoding_error; skip # encoding
def test_encoding_error # encoding
render("foo\nbar\nb\xFEaz".force_encoding("utf-8"))
assert(false, "Expected exception")
rescue Hamlit::Error => e; skip
rescue Hamlit::Error => e
assert_equal(3, e.line)
assert_match(/Invalid .* character/, e.message)
end