Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update item_property to recognize integers #7878

Merged
merged 4 commits into from Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 9 additions & 4 deletions lib/jekyll/filters.rb
Expand Up @@ -371,10 +371,15 @@ def item_property(item, property)
# rubocop:disable Performance/RegexpMatch
# return numeric values as numbers for proper sorting
def parse_sort_input(property)
number_like = %r!\A\s*-?(?:\d+\.?\d*|\.\d+)\s*\Z!
return property.to_f if property.to_s =~ number_like

property
float_like = %r!\A\s*-?(?:\d+\.?\d*|\.\d+)\s*\Z!
integer_like = %r!\A\s*-?\d+\s*\Z!
if property.to_s =~ integer_like
property.to_i
elsif property.to_s =~ float_like
property.to_f
else
property
end
end
# rubocop:enable Performance/RegexpMatch

Expand Down
10 changes: 10 additions & 0 deletions test/test_filters.rb
Expand Up @@ -831,6 +831,16 @@ def to_liquid
)
end
end

should "should pass integers as is" do
grouping = @filter.group_by([
{"name" => "Allison", "year" => 2016},
{"name" => "Amy", "year" => 2016},
{"name" => "George", "year" => 2019},
], "year")
assert_equal "2016", grouping[0]["name"]
assert_equal "2019", grouping[1]["name"]
end
end

context "where filter" do
Expand Down