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:
commit
f3b2ca758e
2 changed files with 10 additions and 5 deletions
|
@ -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|
|
||||
|
|
|
@ -1955,7 +1955,7 @@ 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>
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue