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.
|
# Returns nothing.
|
||||||
def read_yaml(base, name, opts = {})
|
def read_yaml(base, name, opts = {})
|
||||||
|
filename = File.join(base, name)
|
||||||
|
|
||||||
begin
|
begin
|
||||||
self.content = File.read(site.in_source_dir(base, name),
|
self.content = File.read(site.in_source_dir(base, name),
|
||||||
merged_file_read_opts(opts))
|
merged_file_read_opts(opts))
|
||||||
|
@ -50,20 +52,31 @@ module Jekyll
|
||||||
self.data = SafeYAML.load(Regexp.last_match(1))
|
self.data = SafeYAML.load(Regexp.last_match(1))
|
||||||
end
|
end
|
||||||
rescue SyntaxError => e
|
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
|
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
|
end
|
||||||
|
|
||||||
self.data ||= {}
|
self.data ||= {}
|
||||||
|
|
||||||
unless self.data.is_a?(Hash)
|
validate_data! filename
|
||||||
Jekyll.logger.abort_with "Fatal:", "Invalid YAML front matter in #{File.join(base, name)}"
|
validate_permalink! filename
|
||||||
end
|
|
||||||
|
|
||||||
self.data
|
self.data
|
||||||
end
|
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.
|
# Transform the contents based on the content type.
|
||||||
#
|
#
|
||||||
# Returns the transformed contents.
|
# Returns the transformed contents.
|
||||||
|
|
|
@ -2,7 +2,9 @@ module Jekyll
|
||||||
module Errors
|
module Errors
|
||||||
FatalException = Class.new(::RuntimeError)
|
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
|
||||||
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(/invalid byte sequence in UTF-8/, out)
|
||||||
assert_match(/#{File.join(@base, name)}/, out)
|
assert_match(/#{File.join(@base, name)}/, out)
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue