]> gitweb.fluxo.info Git - puppet-stdlib.git/commitdiff
URI.escape for the array case was incorrect.
authorBryon Roché <kain@kain.org>
Fri, 8 Aug 2014 23:59:37 +0000 (16:59 -0700)
committerMorgan Haskel <morgan@puppetlabs.com>
Wed, 4 Mar 2015 00:05:47 +0000 (16:05 -0800)
The previous commit to uriescape() changed the implementation to use the ruby default escape list for URI.escape(), but did not change the call triggered when uriescape() was called on an array, triggering ruby errors.

lib/puppet/parser/functions/uriescape.rb
spec/functions/uriescape_spec.rb

index a486eee50d798d7c5c0ebff71e40173e62e1c291..45bbed22cb580f8c2fe258d26af6fb85859a4804 100644 (file)
@@ -22,7 +22,7 @@ module Puppet::Parser::Functions
 
     if value.is_a?(Array)
       # Numbers in Puppet are often string-encoded which is troublesome ...
-      result = value.collect { |i| i.is_a?(String) ? URI.escape(i,unsafe) : i }
+      result = value.collect { |i| i.is_a?(String) ? URI.escape(i) : i }
     else
       result = URI.escape(value)
     end
index 2321e5aba8aa9f62cd546a0714ef2662bca98315..d0f37de1d4fcbe3e212389751f0115a0bfb32ef0 100755 (executable)
@@ -17,6 +17,13 @@ describe "the uriescape function" do
     expect(result).to(eq(':/?%23[]@!$&\'()*+,;=%20%22%7B%7D'))
   end
 
+  it "should uriescape an array of strings, while not touching up nonstrings" do
+    teststring = ":/?#[]@!$&'()*+,;= \"{}"
+    expectstring = ':/?%23[]@!$&\'()*+,;=%20%22%7B%7D'
+    result = scope.function_uriescape([[teststring, teststring, 1]])
+    expect(result).to(eq([expectstring, expectstring, 1]))
+  end
+
   it "should do nothing if a string is already safe" do
     result = scope.function_uriescape(["ABCdef"])
     expect(result).to(eq('ABCdef'))