diff options
Diffstat (limited to 'spec/ruby/core/string/unpack/shared')
| -rw-r--r-- | spec/ruby/core/string/unpack/shared/basic.rb | 18 | ||||
| -rw-r--r-- | spec/ruby/core/string/unpack/shared/float.rb | 36 | ||||
| -rw-r--r-- | spec/ruby/core/string/unpack/shared/integer.rb | 40 | ||||
| -rw-r--r-- | spec/ruby/core/string/unpack/shared/taint.rb | 79 | ||||
| -rw-r--r-- | spec/ruby/core/string/unpack/shared/unicode.rb | 6 |
5 files changed, 58 insertions, 121 deletions
diff --git a/spec/ruby/core/string/unpack/shared/basic.rb b/spec/ruby/core/string/unpack/shared/basic.rb index 0ecbf615af..2ee2d6899a 100644 --- a/spec/ruby/core/string/unpack/shared/basic.rb +++ b/spec/ruby/core/string/unpack/shared/basic.rb @@ -1,29 +1,27 @@ describe :string_unpack_basic, shared: true do it "ignores whitespace in the format string" do - "abc".unpack("a \t\n\v\f\r"+unpack_format).should be_an_instance_of(Array) + "abc".unpack("a \t\n\v\f\r"+unpack_format).should.instance_of?(Array) end it "calls #to_str to coerce the directives string" do d = mock("unpack directive") d.should_receive(:to_str).and_return("a"+unpack_format) - "abc".unpack(d).should be_an_instance_of(Array) + "abc".unpack(d).should.instance_of?(Array) end - it "raises a TypeError when passed nil" do - lambda { "abc".unpack(nil) }.should raise_error(TypeError) - end - - it "raises a TypeError when passed an Integer" do - lambda { "abc".unpack(1) }.should raise_error(TypeError) + it "raises ArgumentError when a directive is unknown" do + -> { "abcdefgh".unpack("a K" + unpack_format) }.should.raise(ArgumentError, "unknown unpack directive 'K' in 'a K#{unpack_format}'") + -> { "abcdefgh".unpack("a 0" + unpack_format) }.should.raise(ArgumentError, "unknown unpack directive '0' in 'a 0#{unpack_format}'") + -> { "abcdefgh".unpack("a :" + unpack_format) }.should.raise(ArgumentError, "unknown unpack directive ':' in 'a :#{unpack_format}'") end end describe :string_unpack_no_platform, shared: true do it "raises an ArgumentError when the format modifier is '_'" do - lambda { "abcdefgh".unpack(unpack_format("_")) }.should raise_error(ArgumentError) + -> { "abcdefgh".unpack(unpack_format("_")) }.should.raise(ArgumentError) end it "raises an ArgumentError when the format modifier is '!'" do - lambda { "abcdefgh".unpack(unpack_format("!")) }.should raise_error(ArgumentError) + -> { "abcdefgh".unpack(unpack_format("!")) }.should.raise(ArgumentError) end end diff --git a/spec/ruby/core/string/unpack/shared/float.rb b/spec/ruby/core/string/unpack/shared/float.rb index 208dc357af..5525c3fe73 100644 --- a/spec/ruby/core/string/unpack/shared/float.rb +++ b/spec/ruby/core/string/unpack/shared/float.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# encoding: binary describe :string_unpack_float_le, shared: true do it "decodes one float for a single format character" do @@ -53,12 +53,13 @@ describe :string_unpack_float_le, shared: true do it "decodes NaN" do # mumble mumble NaN mumble https://bugs.ruby-lang.org/issues/5884 - [nan_value].pack(unpack_format).unpack(unpack_format).first.nan?.should be_true + [nan_value].pack(unpack_format).unpack(unpack_format).first.nan?.should == true end - it "ignores NULL bytes between directives" do - array = "\x9a\x999@33\xb3?".unpack(unpack_format("\000", 2)) - array.should == [2.9000000953674316, 1.399999976158142] + it "raise ArgumentError for NULL bytes between directives" do + -> { + "\x9a\x999@33\xb3?".unpack(unpack_format("\000", 2)) + }.should.raise(ArgumentError, /unknown unpack directive/) end it "ignores spaces between directives" do @@ -120,12 +121,13 @@ describe :string_unpack_float_be, shared: true do it "decodes NaN" do # mumble mumble NaN mumble https://bugs.ruby-lang.org/issues/5884 - [nan_value].pack(unpack_format).unpack(unpack_format).first.nan?.should be_true + [nan_value].pack(unpack_format).unpack(unpack_format).first.nan?.should == true end - it "ignores NULL bytes between directives" do - array = "@9\x99\x9a?\xb333".unpack(unpack_format("\000", 2)) - array.should == [2.9000000953674316, 1.399999976158142] + it "raise ArgumentError for NULL bytes between directives" do + -> { + "@9\x99\x9a?\xb333".unpack(unpack_format("\000", 2)) + }.should.raise(ArgumentError, /unknown unpack directive/) end it "ignores spaces between directives" do @@ -190,11 +192,13 @@ describe :string_unpack_double_le, shared: true do it "decodes NaN" do # mumble mumble NaN mumble https://bugs.ruby-lang.org/issues/5884 - [nan_value].pack(unpack_format).unpack(unpack_format).first.nan?.should be_true + [nan_value].pack(unpack_format).unpack(unpack_format).first.nan?.should == true end - it "ignores NULL bytes between directives" do - "333333\x07@ffffff\xf6?".unpack(unpack_format("\000", 2)).should == [2.9, 1.4] + it "raise ArgumentError for NULL bytes between directives" do + -> { + "333333\x07@ffffff\xf6?".unpack(unpack_format("\000", 2)) + }.should.raise(ArgumentError, /unknown unpack directive/) end it "ignores spaces between directives" do @@ -258,11 +262,13 @@ describe :string_unpack_double_be, shared: true do it "decodes NaN" do # mumble mumble NaN mumble https://bugs.ruby-lang.org/issues/5884 - [nan_value].pack(unpack_format).unpack(unpack_format).first.nan?.should be_true + [nan_value].pack(unpack_format).unpack(unpack_format).first.nan?.should == true end - it "ignores NULL bytes between directives" do - "@\x07333333?\xf6ffffff".unpack(unpack_format("\000", 2)).should == [2.9, 1.4] + it "raise ArgumentError for NULL bytes between directives" do + -> { + "@\x07333333?\xf6ffffff".unpack(unpack_format("\000", 2)) + }.should.raise(ArgumentError, /unknown unpack directive/) end it "ignores spaces between directives" do diff --git a/spec/ruby/core/string/unpack/shared/integer.rb b/spec/ruby/core/string/unpack/shared/integer.rb index 03dfb5c682..c66156536b 100644 --- a/spec/ruby/core/string/unpack/shared/integer.rb +++ b/spec/ruby/core/string/unpack/shared/integer.rb @@ -1,4 +1,4 @@ -# -*- encoding: ascii-8bit -*- +# encoding: binary describe :string_unpack_16bit_le, shared: true do it "decodes one short for a single format character" do @@ -32,8 +32,10 @@ describe :string_unpack_16bit_le, shared: true do ].should be_computed_by(:unpack, unpack_format(3)) end - it "ignores NULL bytes between directives" do - "abcd".unpack(unpack_format("\000", 2)).should == [25185, 25699] + it "raise ArgumentError for NULL bytes between directives" do + -> { + "abcd".unpack(unpack_format("\000", 2)) + }.should.raise(ArgumentError, /unknown unpack directive/) end it "ignores spaces between directives" do @@ -85,8 +87,10 @@ describe :string_unpack_16bit_be, shared: true do ].should be_computed_by(:unpack, unpack_format(3)) end - it "ignores NULL bytes between directives" do - "badc".unpack(unpack_format("\000", 2)).should == [25185, 25699] + it "raise ArgumentError for NULL bytes between directives" do + -> { + "badc".unpack(unpack_format("\000", 2)) + }.should.raise(ArgumentError, /unknown unpack directive/) end it "ignores spaces between directives" do @@ -139,8 +143,10 @@ describe :string_unpack_32bit_le, shared: true do ].should be_computed_by(:unpack, unpack_format(3)) end - it "ignores NULL bytes between directives" do - "abcdefgh".unpack(unpack_format("\000", 2)).should == [1684234849, 1751606885] + it "raise ArgumentError for NULL bytes between directives" do + -> { + "abcdefgh".unpack(unpack_format("\000", 2)) + }.should.raise(ArgumentError, /unknown unpack directive/) end it "ignores spaces between directives" do @@ -193,8 +199,10 @@ describe :string_unpack_32bit_be, shared: true do ].should be_computed_by(:unpack, unpack_format(3)) end - it "ignores NULL bytes between directives" do - "dcbahgfe".unpack(unpack_format("\000", 2)).should == [1684234849, 1751606885] + it "raise ArgumentError for NULL bytes between directives" do + -> { + "dcbahgfe".unpack(unpack_format("\000", 2)) + }.should.raise(ArgumentError, /unknown unpack directive/) end it "ignores spaces between directives" do @@ -243,9 +251,10 @@ describe :string_unpack_64bit_le, shared: true do "abc".unpack(unpack_format('*')).should == [] end - it "ignores NULL bytes between directives" do - array = "abcdefghabghefcd".unpack(unpack_format("\000", 2)) - array.should == [7523094288207667809, 7233738012216484449] + it "raise ArgumentError for NULL bytes between directives" do + -> { + "badc".unpack(unpack_format("\000", 2)) + }.should.raise(ArgumentError, /unknown unpack directive/) end it "ignores spaces between directives" do @@ -305,9 +314,10 @@ describe :string_unpack_64bit_be, shared: true do "abc".unpack(unpack_format('*')).should == [] end - it "ignores NULL bytes between directives" do - array = "hgfedcbadcfehgba".unpack(unpack_format("\000", 2)) - array.should == [7523094288207667809, 7233738012216484449] + it "raise ArgumentError for NULL bytes between directives" do + -> { + "hgfedcbadcfehgba".unpack(unpack_format("\000", 2)) + }.should.raise(ArgumentError, /unknown unpack directive/) end it "ignores spaces between directives" do diff --git a/spec/ruby/core/string/unpack/shared/taint.rb b/spec/ruby/core/string/unpack/shared/taint.rb index 391338192a..79c7251f01 100644 --- a/spec/ruby/core/string/unpack/shared/taint.rb +++ b/spec/ruby/core/string/unpack/shared/taint.rb @@ -1,81 +1,2 @@ describe :string_unpack_taint, shared: true do - it "does not taint returned arrays if given an untainted format string" do - "".unpack(unpack_format(2)).tainted?.should be_false - end - - it "does not taint returned arrays if given a tainted format string" do - format_string = unpack_format(2).dup - format_string.taint - "".unpack(format_string).tainted?.should be_false - end - - it "does not taint returned strings if given an untainted format string" do - "".unpack(unpack_format(2)).any?(&:tainted?).should be_false - end - - it "does not taint returned strings if given a tainted format string" do - format_string = unpack_format(2).dup - format_string.taint - "".unpack(format_string).any?(&:tainted?).should be_false - end - - it "does not taint returned arrays if given an untainted packed string" do - "".unpack(unpack_format(2)).tainted?.should be_false - end - - it "does not taint returned arrays if given a tainted packed string" do - packed_string = "" - packed_string.taint - packed_string.unpack(unpack_format(2)).tainted?.should be_false - end - - it "does not taint returned strings if given an untainted packed string" do - "".unpack(unpack_format(2)).any?(&:tainted?).should be_false - end - - it "taints returned strings if given a tainted packed string" do - packed_string = "" - packed_string.taint - packed_string.unpack(unpack_format(2)).all?(&:tainted?).should be_true - end - - it "does not untrust returned arrays if given an untrusted format string" do - "".unpack(unpack_format(2)).untrusted?.should be_false - end - - it "does not untrust returned arrays if given a untrusted format string" do - format_string = unpack_format(2).dup - format_string.untrust - "".unpack(format_string).untrusted?.should be_false - end - - it "does not untrust returned strings if given an untainted format string" do - "".unpack(unpack_format(2)).any?(&:untrusted?).should be_false - end - - it "does not untrust returned strings if given a untrusted format string" do - format_string = unpack_format(2).dup - format_string.untrust - "".unpack(format_string).any?(&:untrusted?).should be_false - end - - it "does not untrust returned arrays if given an trusted packed string" do - "".unpack(unpack_format(2)).untrusted?.should be_false - end - - it "does not untrust returned arrays if given a untrusted packed string" do - packed_string = "" - packed_string.untrust - packed_string.unpack(unpack_format(2)).untrusted?.should be_false - end - - it "does not untrust returned strings if given an trusted packed string" do - "".unpack(unpack_format(2)).any?(&:untrusted?).should be_false - end - - it "untrusts returned strings if given a untrusted packed string" do - packed_string = "" - packed_string.untrust - packed_string.unpack(unpack_format(2)).all?(&:untrusted?).should be_true - end end diff --git a/spec/ruby/core/string/unpack/shared/unicode.rb b/spec/ruby/core/string/unpack/shared/unicode.rb index a2b4e142b2..9b4e0c09de 100644 --- a/spec/ruby/core/string/unpack/shared/unicode.rb +++ b/spec/ruby/core/string/unpack/shared/unicode.rb @@ -50,8 +50,10 @@ describe :string_unpack_unicode, shared: true do "\xc2\x80".unpack("UUUU").should == [0x80] end - it "ignores NULL bytes between directives" do - "\x01\x02".unpack("U\x00U").should == [1, 2] + it "raise ArgumentError for NULL bytes between directives" do + -> { + "\x01\x02".unpack("U\x00U") + }.should.raise(ArgumentError, /unknown unpack directive/) end it "ignores spaces between directives" do |
