-
Notifications
You must be signed in to change notification settings - Fork 268
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix template expand level 2 hash support for non-string objects #499
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -896,19 +896,16 @@ def join_values(operator, return_value) | |
# | ||
# @return [Hash, Array, String] The normalized values | ||
def normalize_value(value) | ||
unless value.is_a?(Hash) | ||
value = value.respond_to?(:to_ary) ? value.to_ary : value.to_str | ||
end | ||
|
||
# Handle unicode normalization | ||
if value.kind_of?(Array) | ||
value.map! { |val| normalize_value(val) } | ||
if value.respond_to?(:to_ary) | ||
value.to_ary.map! { |val| normalize_value(val) } | ||
elsif value.kind_of?(Hash) | ||
value = value.inject({}) { |acc, (k, v)| | ||
acc[normalize_value(k)] = normalize_value(v) | ||
acc | ||
} | ||
else | ||
value = value.to_s if !value.kind_of?(String) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And this is the fix basically, restoring the |
||
if value.encoding != Encoding::UTF_8 | ||
value = value.dup.force_encoding(Encoding::UTF_8) | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -209,7 +209,7 @@ | |
:path => "/foo/bar", | ||
:semi => ";", | ||
:list => %w(red green blue), | ||
:keys => {"semi" => ';', "dot" => '.', "comma" => ','} | ||
:keys => {"semi" => ';', "dot" => '.', :comma => ','} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed this specs are weird to write (you need to write a big array of expected outputs in different orders, probably legacy ruby 1.8 stuff when hash where unordered). So I just modified existing specs here to make it simple. I'll probably make another PR to simplify those specs after I confirm it was only for ruby 1.8. |
||
} | ||
} | ||
context "Expansion with value modifiers" do | ||
|
@@ -404,7 +404,7 @@ | |
{ | ||
:var => "value", | ||
:semi => ";", | ||
:year => %w(1965 2000 2012), | ||
:year => [1965, 2000, 2012], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And this was a good existing example to test integers too 👍 |
||
:dom => %w(example com) | ||
} | ||
} | ||
|
@@ -437,7 +437,7 @@ | |
:base => "http://example.com/home/", | ||
:path => "/foo/bar", | ||
:list => ["red", "green", "blue"], | ||
:keys => {"semi" => ";","dot" => ".","comma" => ","}, | ||
:keys => {"semi" => ";","dot" => ".",:comma => ","}, | ||
:v => "6", | ||
:x => "1024", | ||
:y => "768", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I just simplified a bit the code, treating all array-like object in the same place instead of having the first like (900) to convert first.