diff --git a/lib/addressable/template.rb b/lib/addressable/template.rb index 42cbf7cc..bc520415 100644 --- a/lib/addressable/template.rb +++ b/lib/addressable/template.rb @@ -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) if value.encoding != Encoding::UTF_8 value = value.dup.force_encoding(Encoding::UTF_8) end diff --git a/spec/addressable/template_spec.rb b/spec/addressable/template_spec.rb index 4b54ea96..5cac63ec 100644 --- a/spec/addressable/template_spec.rb +++ b/spec/addressable/template_spec.rb @@ -209,7 +209,7 @@ :path => "/foo/bar", :semi => ";", :list => %w(red green blue), - :keys => {"semi" => ';', "dot" => '.', "comma" => ','} + :keys => {"semi" => ';', "dot" => '.', :comma => ','} } } context "Expansion with value modifiers" do @@ -404,7 +404,7 @@ { :var => "value", :semi => ";", - :year => %w(1965 2000 2012), + :year => [1965, 2000, 2012], :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",