Date filters should never raise an exception (#5722)
Merge pull request 5722
This commit is contained in:
parent
4d689ec051
commit
52ac75b484
|
@ -80,6 +80,7 @@ module Jekyll
|
||||||
#
|
#
|
||||||
# Returns the formatted String.
|
# Returns the formatted String.
|
||||||
def date_to_long_string(date)
|
def date_to_long_string(date)
|
||||||
|
return date if date.to_s.empty?
|
||||||
time(date).strftime("%d %B %Y")
|
time(date).strftime("%d %B %Y")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -94,6 +95,7 @@ module Jekyll
|
||||||
#
|
#
|
||||||
# Returns the formatted String.
|
# Returns the formatted String.
|
||||||
def date_to_xmlschema(date)
|
def date_to_xmlschema(date)
|
||||||
|
return date if date.to_s.empty?
|
||||||
time(date).xmlschema
|
time(date).xmlschema
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -108,6 +110,7 @@ module Jekyll
|
||||||
#
|
#
|
||||||
# Returns the formatted String.
|
# Returns the formatted String.
|
||||||
def date_to_rfc822(date)
|
def date_to_rfc822(date)
|
||||||
|
return date if date.to_s.empty?
|
||||||
time(date).rfc822
|
time(date).rfc822
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -284,11 +284,9 @@ class TestFilters < JekyllUnitTest
|
||||||
end
|
end
|
||||||
|
|
||||||
context "without input" do
|
context "without input" do
|
||||||
should "raise an error if input is nil" do
|
should "return input" do
|
||||||
err = assert_raises Jekyll::Errors::InvalidDateError do
|
assert_nil(@filter.date_to_xmlschema(nil))
|
||||||
@filter.date_to_xmlschema(nil)
|
assert_equal("", @filter.date_to_xmlschema(""))
|
||||||
end
|
|
||||||
assert_equal "Invalid Date: 'nil' is not a valid datetime.", err.message
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue