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:
Parker Moore 2015-03-05 13:14:29 -08:00
commit 6b4219f0e2
3 changed files with 10 additions and 0 deletions

View File

@ -49,6 +49,7 @@
* Use consistent syntax for deprecation warning (#3535)
* Added build --destination and --source flags (#3418)
* Site template: remove unused `page.meta` attribute (#3537)
* Improve the error message when sorting null objects (#3520)
### Bug Fixes

View File

@ -222,6 +222,9 @@ module Jekyll
#
# Returns the filtered array of objects
def sort(input, property = nil, nils = "first")
if input.nil?
raise ArgumentError.new("Cannot sort a null object.")
end
if property.nil?
input.sort
else

View File

@ -280,6 +280,12 @@ class TestFilters < JekyllUnitTest
end
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
assert_equal [1, 2, 2.2, 3], @filter.sort([3, 2.2, 2, 1])
end