diff --git a/lib/addressable/template.rb b/lib/addressable/template.rb index bc520415..68506947 100644 --- a/lib/addressable/template.rb +++ b/lib/addressable/template.rb @@ -922,6 +922,7 @@ def normalize_value(value) # @return [Hash] # A hash with stringified keys def normalize_keys(mapping) + return mapping unless mapping.respond_to?(:inject) return mapping.inject({}) do |accu, pair| name, value = pair if Symbol === name diff --git a/spec/addressable/template_spec.rb b/spec/addressable/template_spec.rb index 24616c23..df3743dd 100644 --- a/spec/addressable/template_spec.rb +++ b/spec/addressable/template_spec.rb @@ -102,6 +102,12 @@ } end +describe "Substituting from an optional block" do + sub = lambda { |x| "foo-#{x}" } + + Addressable::Template.new("{bar}/{baz}").expand(sub).to_str.should == "foo-bar/foo-baz" +end + describe "Level 1:" do subject { {:var => "value", :hello => "Hello World!"}