diff options
author | Markus Roberts <Markus@reality.com> | 2010-10-12 16:38:59 -0700 |
---|---|---|
committer | Markus Roberts <Markus@reality.com> | 2010-10-13 16:49:53 -0700 |
commit | 3c56705a95c945778674f9792a07b66b879cb48e (patch) | |
tree | 76c0a5807b3ad64138d24b6f189b0dda60255bdf /spec | |
parent | e232770baefc35abb71de6e2f28d053158e6dd45 (diff) | |
download | puppet-3c56705a95c945778674f9792a07b66b879cb48e.tar.gz puppet-3c56705a95c945778674f9792a07b66b879cb48e.tar.xz puppet-3c56705a95c945778674f9792a07b66b879cb48e.zip |
Fix for #4832 -- Making PSON handle arbitrary binary data
The PSON library needlessly assumed that the data to be transmitted was well-
formed unicode. This made Latin-1 users (and anyone who needed to serialize
arbitrary binary data) sad. This patch goes some of the way to resolving the
issues, by passing through non-unicode data rather than just failing, adds
tests, and cleans up a pernicious assumption about escape characters in ruby
regular expressions not marked "n" (no-encoding).
Diffstat (limited to 'spec')
-rwxr-xr-x | spec/unit/util/pson_spec.rb (renamed from spec/unit/util/json_spec.rb) | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/spec/unit/util/json_spec.rb b/spec/unit/util/pson_spec.rb index 4f6cea997..d02d28517 100755 --- a/spec/unit/util/json_spec.rb +++ b/spec/unit/util/pson_spec.rb @@ -18,4 +18,21 @@ describe Puppet::Util::Pson do pson.expects(:from_pson).with("mydata") pson.pson_create("type" => "foo", "data" => "mydata") end + + + { + 'foo' => '"foo"', + 1 => '1', + "\x80" => "\"\x80\"", + [] => '[]' + }.each { |str,pson| + it "should be able to encode #{str.inspect}" do + str.to_pson.should == pson + end + } + + it "should be able to handle arbitrary binary data" do + bin_string = (1..20000).collect { |i| ((17*i+13*i*i) % 255).chr }.join + PSON.parse(%Q{{ "type": "foo", "data": #{bin_string.to_pson} }})["data"].should == bin_string + end end |