Date filters should never raise an exception (#5722)

Merge pull request 5722
This commit is contained in:
jekyllbot 2017-04-04 19:47:11 -04:00 committed by GitHub
parent 4d689ec051
commit 52ac75b484
2 changed files with 6 additions and 5 deletions

View File

@ -80,6 +80,7 @@ module Jekyll
#
# Returns the formatted String.
def date_to_long_string(date)
return date if date.to_s.empty?
time(date).strftime("%d %B %Y")
end
@ -94,6 +95,7 @@ module Jekyll
#
# Returns the formatted String.
def date_to_xmlschema(date)
return date if date.to_s.empty?
time(date).xmlschema
end
@ -108,6 +110,7 @@ module Jekyll
#
# Returns the formatted String.
def date_to_rfc822(date)
return date if date.to_s.empty?
time(date).rfc822
end

View File

@ -284,11 +284,9 @@ class TestFilters < JekyllUnitTest
end
context "without input" do
should "raise an error if input is nil" do
err = assert_raises Jekyll::Errors::InvalidDateError do
@filter.date_to_xmlschema(nil)
end
assert_equal "Invalid Date: 'nil' is not a valid datetime.", err.message
should "return input" do
assert_nil(@filter.date_to_xmlschema(nil))
assert_equal("", @filter.date_to_xmlschema(""))
end
end
end