Merge branch 'message-for-yaml-error' of https://github.com/stereobooster/jekyll into stereobooster-message-for-yaml-error
This commit is contained in:
commit
2c0b3b33d9
|
@ -25,14 +25,16 @@ module Jekyll
|
||||||
#
|
#
|
||||||
# Returns nothing.
|
# Returns nothing.
|
||||||
def read_yaml(base, name)
|
def read_yaml(base, name)
|
||||||
self.content = File.read(File.join(base, name))
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
self.content = File.read(File.join(base, name))
|
||||||
|
|
||||||
if self.content =~ /\A(---\s*\n.*?\n?)^(---\s*$\n?)/m
|
if self.content =~ /\A(---\s*\n.*?\n?)^(---\s*$\n?)/m
|
||||||
self.content = $POSTMATCH
|
self.content = $POSTMATCH
|
||||||
self.data = YAML.load($1)
|
self.data = YAML.load($1)
|
||||||
end
|
end
|
||||||
rescue => e
|
rescue => e
|
||||||
|
puts "Error reading file #{name}: #{e.message}"
|
||||||
|
rescue SyntaxError => e
|
||||||
puts "YAML Exception reading #{name}: #{e.message}"
|
puts "YAML Exception reading #{name}: #{e.message}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
---
|
||||||
|
bad yaml: [
|
||||||
|
---
|
||||||
|
Real content starts here
|
|
@ -0,0 +1,7 @@
|
||||||
|
---
|
||||||
|
test: good
|
||||||
|
---
|
||||||
|
Real content starts here
|
||||||
|
|
||||||
|
Ðóññêèé òåêñò
|
||||||
|
|
|
@ -31,4 +31,14 @@ class Test::Unit::TestCase
|
||||||
def clear_dest
|
def clear_dest
|
||||||
FileUtils.rm_rf(dest_dir)
|
FileUtils.rm_rf(dest_dir)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def capture_stdout
|
||||||
|
$old_stdout = $stdout
|
||||||
|
$stdout = StringIO.new
|
||||||
|
yield
|
||||||
|
$stdout.rewind
|
||||||
|
return $stdout.string
|
||||||
|
ensure
|
||||||
|
$stdout = $old_stdout
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,5 +18,23 @@ class TestConvertible < Test::Unit::TestCase
|
||||||
ret = @convertible.read_yaml(@base, 'broken_front_matter1.erb')
|
ret = @convertible.read_yaml(@base, 'broken_front_matter1.erb')
|
||||||
assert_equal({}, ret)
|
assert_equal({}, ret)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "not parse if there is syntax error in front-matter" do
|
||||||
|
out = capture_stdout do
|
||||||
|
ret = @convertible.read_yaml(@base, 'broken_front_matter2.erb')
|
||||||
|
assert_equal({}, ret)
|
||||||
|
end
|
||||||
|
assert_match(/YAML Exception|syntax error/, out)
|
||||||
|
end
|
||||||
|
|
||||||
|
if RUBY_VERSION >= '1.9.2'
|
||||||
|
should "not parse if there is encoding error in file" do
|
||||||
|
out = capture_stdout do
|
||||||
|
ret = @convertible.read_yaml(@base, 'broken_front_matter3.erb')
|
||||||
|
assert_equal({}, ret)
|
||||||
|
end
|
||||||
|
assert_match(/invalid byte sequence in UTF-8/, out)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue