Merge branch 'master' of github.com:jekyll/jekyll
* 'master' of github.com:jekyll/jekyll: Update history to reflect merge of #3520 [ci skip] Corrected error message as suggested by @parkr. Improved clarity of sort nil input error message. Added test to check on nil input for sort filter. Sort will now raise error on nil object array input.
This commit is contained in:
commit
6b4219f0e2
|
@ -49,6 +49,7 @@
|
||||||
* Use consistent syntax for deprecation warning (#3535)
|
* Use consistent syntax for deprecation warning (#3535)
|
||||||
* Added build --destination and --source flags (#3418)
|
* Added build --destination and --source flags (#3418)
|
||||||
* Site template: remove unused `page.meta` attribute (#3537)
|
* Site template: remove unused `page.meta` attribute (#3537)
|
||||||
|
* Improve the error message when sorting null objects (#3520)
|
||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
|
|
||||||
|
|
|
@ -222,6 +222,9 @@ module Jekyll
|
||||||
#
|
#
|
||||||
# Returns the filtered array of objects
|
# Returns the filtered array of objects
|
||||||
def sort(input, property = nil, nils = "first")
|
def sort(input, property = nil, nils = "first")
|
||||||
|
if input.nil?
|
||||||
|
raise ArgumentError.new("Cannot sort a null object.")
|
||||||
|
end
|
||||||
if property.nil?
|
if property.nil?
|
||||||
input.sort
|
input.sort
|
||||||
else
|
else
|
||||||
|
|
|
@ -280,6 +280,12 @@ class TestFilters < JekyllUnitTest
|
||||||
end
|
end
|
||||||
|
|
||||||
context "sort filter" do
|
context "sort filter" do
|
||||||
|
should "raise Exception when input is nil" do
|
||||||
|
err = assert_raises ArgumentError do
|
||||||
|
@filter.sort(nil)
|
||||||
|
end
|
||||||
|
assert_equal "Cannot sort a null object.", err.message
|
||||||
|
end
|
||||||
should "return sorted numbers" do
|
should "return sorted numbers" do
|
||||||
assert_equal [1, 2, 2.2, 3], @filter.sort([3, 2.2, 2, 1])
|
assert_equal [1, 2, 2.2, 3], @filter.sort([3, 2.2, 2, 1])
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue