summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2009-03-10 00:48:13 -0500
committerLuke Kanies <luke@madstop.com>2009-03-10 00:48:13 -0500
commitd0fc2f5738a78c51128f6377c03fe42cf50371a0 (patch)
tree340ba2bb55f823b5cc180b9a4848456310aebda3
parent90afd48c39bc7bbb8e7afa81a49d2f814a787565 (diff)
downloadpuppet-d0fc2f5738a78c51128f6377c03fe42cf50371a0.tar.gz
puppet-d0fc2f5738a78c51128f6377c03fe42cf50371a0.tar.xz
puppet-d0fc2f5738a78c51128f6377c03fe42cf50371a0.zip
Correctly handling numerical REST arguments
Signed-off-by: Luke Kanies <luke@madstop.com>
-rw-r--r--lib/puppet/indirector/rest.rb1
-rw-r--r--lib/puppet/network/http/handler.rb2
-rwxr-xr-xspec/unit/indirector/rest.rb10
-rwxr-xr-xspec/unit/network/http/mongrel/rest.rb12
4 files changed, 25 insertions, 0 deletions
diff --git a/lib/puppet/indirector/rest.rb b/lib/puppet/indirector/rest.rb
index ce459b905..23ed56dee 100644
--- a/lib/puppet/indirector/rest.rb
+++ b/lib/puppet/indirector/rest.rb
@@ -94,6 +94,7 @@ class Puppet::Indirector::REST < Puppet::Indirector::Terminus
case value
when nil; next
when true, false; value = value.to_s
+ when Fixnum, Bignum, Float; value = value # nothing
when String; value = URI.escape(value)
when Symbol; value = URI.escape(value.to_s)
when Array; value = URI.escape(YAML.dump(value))
diff --git a/lib/puppet/network/http/handler.rb b/lib/puppet/network/http/handler.rb
index cce679864..7f6bd4111 100644
--- a/lib/puppet/network/http/handler.rb
+++ b/lib/puppet/network/http/handler.rb
@@ -193,6 +193,8 @@ module Puppet::Network::HTTP::Handler
else
value = true if value == "true"
value = false if value == "false"
+ value = Integer(value) if value =~ /^\d+$/
+ value = value.to_f if value =~ /^\d+\.\d+$/
end
result[param.to_sym] = value
result
diff --git a/spec/unit/indirector/rest.rb b/spec/unit/indirector/rest.rb
index 4fa30b20a..8ed50d300 100755
--- a/spec/unit/indirector/rest.rb
+++ b/spec/unit/indirector/rest.rb
@@ -194,6 +194,16 @@ describe Puppet::Indirector::REST do
@searcher.query_string(@request).should == "?one=#{escaping}"
end
+ it "should convert to a string all option values that are integers" do
+ @request.stubs(:options).returns(:one => 50)
+ @searcher.query_string(@request).should == "?one=50"
+ end
+
+ it "should convert to a string all option values that are floating point numbers" do
+ @request.stubs(:options).returns(:one => 1.2)
+ @searcher.query_string(@request).should == "?one=1.2"
+ end
+
it "should convert to a string and URI-escape all option values that are symbols" do
escaping = URI.escape("sym bol")
@request.stubs(:options).returns(:one => :"sym bol")
diff --git a/spec/unit/network/http/mongrel/rest.rb b/spec/unit/network/http/mongrel/rest.rb
index e72d4f540..c03698dbd 100755
--- a/spec/unit/network/http/mongrel/rest.rb
+++ b/spec/unit/network/http/mongrel/rest.rb
@@ -128,6 +128,18 @@ describe "Puppet::Network::HTTP::MongrelREST" do
result[:foo].should be_false
end
+ it "should convert integer arguments to Integers" do
+ @request.expects(:params).returns('QUERY_STRING' => 'foo=15')
+ result = @handler.params(@request)
+ result[:foo].should == 15
+ end
+
+ it "should convert floating point arguments to Floats" do
+ @request.expects(:params).returns('QUERY_STRING' => 'foo=1.5')
+ result = @handler.params(@request)
+ result[:foo].should == 1.5
+ end
+
it "should YAML-load and URI-decode values that are YAML-encoded" do
escaping = URI.escape(YAML.dump(%w{one two}))
@request.expects(:params).returns('QUERY_STRING' => "foo=#{escaping}")