Merge pull request #4361 from jekyll/pheuko-empty-permalink
Merge pull request 4361
This commit is contained in:
commit
0daafd7bda
|
@ -42,6 +42,8 @@ module Jekyll
|
|||
#
|
||||
# Returns nothing.
|
||||
def read_yaml(base, name, opts = {})
|
||||
filename = File.join(base, name)
|
||||
|
||||
begin
|
||||
self.content = File.read(site.in_source_dir(base, name),
|
||||
merged_file_read_opts(opts))
|
||||
|
@ -50,20 +52,31 @@ module Jekyll
|
|||
self.data = SafeYAML.load(Regexp.last_match(1))
|
||||
end
|
||||
rescue SyntaxError => e
|
||||
Jekyll.logger.warn "YAML Exception reading #{File.join(base, name)}: #{e.message}"
|
||||
Jekyll.logger.warn "YAML Exception reading #{filename}: #{e.message}"
|
||||
rescue Exception => e
|
||||
Jekyll.logger.warn "Error reading file #{File.join(base, name)}: #{e.message}"
|
||||
Jekyll.logger.warn "Error reading file #{filename}: #{e.message}"
|
||||
end
|
||||
|
||||
self.data ||= {}
|
||||
|
||||
unless self.data.is_a?(Hash)
|
||||
Jekyll.logger.abort_with "Fatal:", "Invalid YAML front matter in #{File.join(base, name)}"
|
||||
end
|
||||
validate_data! filename
|
||||
validate_permalink! filename
|
||||
|
||||
self.data
|
||||
end
|
||||
|
||||
def validate_data!(filename)
|
||||
unless self.data.is_a?(Hash)
|
||||
raise Errors::InvalidYAMLFrontMatterError, "Invalid YAML front matter in #{filename}"
|
||||
end
|
||||
end
|
||||
|
||||
def validate_permalink!(filename)
|
||||
if self.data['permalink'] && self.data['permalink'].size == 0
|
||||
raise Errors::InvalidPermalinkError, "Invalid permalink in #{filename}"
|
||||
end
|
||||
end
|
||||
|
||||
# Transform the contents based on the content type.
|
||||
#
|
||||
# Returns the transformed contents.
|
||||
|
|
|
@ -2,7 +2,9 @@ module Jekyll
|
|||
module Errors
|
||||
FatalException = Class.new(::RuntimeError)
|
||||
|
||||
MissingDependencyException = Class.new(FatalException)
|
||||
DropMutationException = Class.new(FatalException)
|
||||
DropMutationException = Class.new(FatalException)
|
||||
InvalidPermalinkError = Class.new(FatalException)
|
||||
InvalidYAMLFrontMatterError = Class.new(FatalException)
|
||||
MissingDependencyException = Class.new(FatalException)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
permalink: ''
|
||||
---
|
||||
Empty Permalink
|
|
@ -49,5 +49,19 @@ class TestConvertible < JekyllUnitTest
|
|||
assert_match(/invalid byte sequence in UTF-8/, out)
|
||||
assert_match(/#{File.join(@base, name)}/, out)
|
||||
end
|
||||
|
||||
should "parse the front-matter but show an error if permalink is empty" do
|
||||
name = 'empty_permalink.erb'
|
||||
assert_raises(Errors::InvalidPermalinkError) do
|
||||
@convertible.read_yaml(@base, name)
|
||||
end
|
||||
end
|
||||
|
||||
should "parse the front-matter correctly whitout permalink" do
|
||||
out = capture_stderr do
|
||||
@convertible.read_yaml(@base, 'front_matter.erb')
|
||||
end
|
||||
refute_match(/Invalid permalink/, out)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue