summaryrefslogtreecommitdiff
path: root/spec/ruby/core/string
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/string')
-rw-r--r--spec/ruby/core/string/chars_spec.rb3
-rw-r--r--spec/ruby/core/string/codepoints_spec.rb4
-rw-r--r--spec/ruby/core/string/each_grapheme_cluster_spec.rb11
-rw-r--r--spec/ruby/core/string/fixtures/classes.rb2
-rw-r--r--spec/ruby/core/string/grapheme_clusters_spec.rb15
-rw-r--r--spec/ruby/core/string/lines_spec.rb2
-rw-r--r--spec/ruby/core/string/modulo_spec.rb17
-rw-r--r--spec/ruby/core/string/shared/grapheme_clusters.rb16
-rw-r--r--spec/ruby/core/string/slice_spec.rb48
-rw-r--r--spec/ruby/core/string/split_spec.rb10
-rw-r--r--spec/ruby/core/string/unpack/a_spec.rb3
-rw-r--r--spec/ruby/core/string/unpack/b_spec.rb3
-rw-r--r--spec/ruby/core/string/unpack/h_spec.rb3
-rw-r--r--spec/ruby/core/string/unpack/m_spec.rb3
-rw-r--r--spec/ruby/core/string/unpack/p_spec.rb43
-rw-r--r--spec/ruby/core/string/unpack/shared/taint.rb81
-rw-r--r--spec/ruby/core/string/unpack/u_spec.rb3
-rw-r--r--spec/ruby/core/string/unpack/z_spec.rb2
18 files changed, 233 insertions, 36 deletions
diff --git a/spec/ruby/core/string/chars_spec.rb b/spec/ruby/core/string/chars_spec.rb
index 54876f9f9d..e4f26bc0cc 100644
--- a/spec/ruby/core/string/chars_spec.rb
+++ b/spec/ruby/core/string/chars_spec.rb
@@ -5,7 +5,6 @@ describe "String#chars" do
it_behaves_like :string_chars, :chars
it "returns an array when no block given" do
- ary = "hello".send(@method)
- ary.should == ['h', 'e', 'l', 'l', 'o']
+ "hello".chars.should == ['h', 'e', 'l', 'l', 'o']
end
end
diff --git a/spec/ruby/core/string/codepoints_spec.rb b/spec/ruby/core/string/codepoints_spec.rb
index 66f2884168..bccb3d0484 100644
--- a/spec/ruby/core/string/codepoints_spec.rb
+++ b/spec/ruby/core/string/codepoints_spec.rb
@@ -8,13 +8,13 @@ with_feature :encoding do
it_behaves_like :string_codepoints, :codepoints
it "returns an Array when no block is given" do
- "abc".send(@method).should == [?a.ord, ?b.ord, ?c.ord]
+ "abc".codepoints.should == [?a.ord, ?b.ord, ?c.ord]
end
it "raises an ArgumentError when no block is given if self has an invalid encoding" do
s = "\xDF".force_encoding(Encoding::UTF_8)
s.valid_encoding?.should be_false
- lambda {s.send(@method)}.should raise_error(ArgumentError)
+ lambda { s.codepoints }.should raise_error(ArgumentError)
end
end
end
diff --git a/spec/ruby/core/string/each_grapheme_cluster_spec.rb b/spec/ruby/core/string/each_grapheme_cluster_spec.rb
new file mode 100644
index 0000000000..5367f84887
--- /dev/null
+++ b/spec/ruby/core/string/each_grapheme_cluster_spec.rb
@@ -0,0 +1,11 @@
+require_relative 'shared/chars'
+require_relative 'shared/grapheme_clusters'
+require_relative 'shared/each_char_without_block'
+
+ruby_version_is "2.5" do
+ describe "String#each_grapheme_cluster" do
+ it_behaves_like :string_chars, :each_grapheme_cluster
+ it_behaves_like :string_grapheme_clusters, :each_grapheme_cluster
+ it_behaves_like :string_each_char_without_block, :each_grapheme_cluster
+ end
+end
diff --git a/spec/ruby/core/string/fixtures/classes.rb b/spec/ruby/core/string/fixtures/classes.rb
index 6af106f9d3..1cc7600abb 100644
--- a/spec/ruby/core/string/fixtures/classes.rb
+++ b/spec/ruby/core/string/fixtures/classes.rb
@@ -4,7 +4,7 @@ class Object
def unpack_format(count=nil, repeat=nil)
format = "#{instance_variable_get(:@method)}#{count}"
format *= repeat if repeat
- format
+ format.dup # because it may then become tainted
end
end
diff --git a/spec/ruby/core/string/grapheme_clusters_spec.rb b/spec/ruby/core/string/grapheme_clusters_spec.rb
new file mode 100644
index 0000000000..0cba0e4216
--- /dev/null
+++ b/spec/ruby/core/string/grapheme_clusters_spec.rb
@@ -0,0 +1,15 @@
+require_relative 'shared/chars'
+require_relative 'shared/grapheme_clusters'
+
+ruby_version_is "2.5" do
+ describe "String#grapheme_clusters" do
+ it_behaves_like :string_chars, :grapheme_clusters
+ it_behaves_like :string_grapheme_clusters, :grapheme_clusters
+
+ it "returns an array when no block given" do
+ string = "ab\u{1f3f3}\u{fe0f}\u{200d}\u{1f308}\u{1F43E}"
+ string.grapheme_clusters.should == ['a', 'b', "\u{1f3f3}\u{fe0f}\u{200d}\u{1f308}", "\u{1F43E}"]
+
+ end
+ end
+end
diff --git a/spec/ruby/core/string/lines_spec.rb b/spec/ruby/core/string/lines_spec.rb
index 6b2d74daf1..1c13936c30 100644
--- a/spec/ruby/core/string/lines_spec.rb
+++ b/spec/ruby/core/string/lines_spec.rb
@@ -7,7 +7,7 @@ describe "String#lines" do
it_behaves_like :string_each_line, :lines
it "returns an array when no block given" do
- ary = "hello world".send(@method, ' ')
+ ary = "hello world".lines(' ')
ary.should == ["hello ", "world"]
end
diff --git a/spec/ruby/core/string/modulo_spec.rb b/spec/ruby/core/string/modulo_spec.rb
index e81b27e4ce..72738ece24 100644
--- a/spec/ruby/core/string/modulo_spec.rb
+++ b/spec/ruby/core/string/modulo_spec.rb
@@ -19,6 +19,23 @@ describe "String#%" do
("%d%% %s" % [10, "of chickens!"]).should == "10% of chickens!"
end
+ describe "output's encoding" do
+ it "is the same as the format string if passed value is encoding-compatible" do
+ [Encoding::ASCII_8BIT, Encoding::US_ASCII, Encoding::UTF_8, Encoding::SHIFT_JIS].each do |encoding|
+ ("hello %s!".encode(encoding) % "world").encoding.should == encoding
+ end
+ end
+
+ it "negotiates a compatible encoding if necessary" do
+ ("hello %s" % 195.chr).encoding.should == Encoding::ASCII_8BIT
+ ("hello %s".encode("shift_jis") % "wörld").encoding.should == Encoding::UTF_8
+ end
+
+ it "raises if a compatible encoding can't be found" do
+ lambda { "hello %s".encode("utf-8") % "world".encode("UTF-16LE") }.should raise_error(Encoding::CompatibilityError)
+ end
+ end
+
ruby_version_is ""..."2.5" do
it "formats single % character at the end as literal %" do
("%" % []).should == "%"
diff --git a/spec/ruby/core/string/shared/grapheme_clusters.rb b/spec/ruby/core/string/shared/grapheme_clusters.rb
new file mode 100644
index 0000000000..8b666868b1
--- /dev/null
+++ b/spec/ruby/core/string/shared/grapheme_clusters.rb
@@ -0,0 +1,16 @@
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+
+describe :string_grapheme_clusters, shared: true do
+ it "passes each grapheme cluster in self to the given block" do
+ a = []
+ # test string: abc[rainbow flag emoji][paw prints]
+ "ab\u{1f3f3}\u{fe0f}\u{200d}\u{1f308}\u{1F43E}".send(@method) { |c| a << c }
+ a.should == ['a', 'b', "\u{1f3f3}\u{fe0f}\u{200d}\u{1f308}", "\u{1F43E}"]
+ end
+
+ it "returns self" do
+ s = StringSpecs::MyString.new "ab\u{1f3f3}\u{fe0f}\u{200d}\u{1f308}\u{1F43E}"
+ s.send(@method) {}.should equal(s)
+ end
+end
diff --git a/spec/ruby/core/string/slice_spec.rb b/spec/ruby/core/string/slice_spec.rb
index 12876e757d..a3e9d6b74f 100644
--- a/spec/ruby/core/string/slice_spec.rb
+++ b/spec/ruby/core/string/slice_spec.rb
@@ -75,9 +75,9 @@ describe "String#slice! with index" do
with_feature :encoding do
it "returns the character given by the character index" do
- "hellö there".send(@method, 1).should == "e"
- "hellö there".send(@method, 4).should == "ö"
- "hellö there".send(@method, 6).should == "t"
+ "hellö there".slice!(1).should == "e"
+ "hellö there".slice!(4).should == "ö"
+ "hellö there".slice!(6).should == "t"
end
end
@@ -151,15 +151,15 @@ describe "String#slice! with index, length" do
with_feature :encoding do
it "returns the substring given by the character offsets" do
- "hellö there".send(@method, 1,0).should == ""
- "hellö there".send(@method, 1,3).should == "ell"
- "hellö there".send(@method, 1,6).should == "ellö t"
- "hellö there".send(@method, 1,9).should == "ellö ther"
+ "hellö there".slice!(1,0).should == ""
+ "hellö there".slice!(1,3).should == "ell"
+ "hellö there".slice!(1,6).should == "ellö t"
+ "hellö there".slice!(1,9).should == "ellö ther"
end
it "treats invalid bytes as single bytes" do
xE6xCB = [0xE6,0xCB].pack('CC').force_encoding('utf-8')
- "a#{xE6xCB}b".send(@method, 1, 2).should == xE6xCB
+ "a#{xE6xCB}b".slice!(1, 2).should == xE6xCB
end
end
end
@@ -239,13 +239,13 @@ describe "String#slice! Range" do
with_feature :encoding do
it "returns the substring given by the character offsets of the range" do
- "hellö there".send(@method, 1..1).should == "e"
- "hellö there".send(@method, 1..3).should == "ell"
- "hellö there".send(@method, 1...3).should == "el"
- "hellö there".send(@method, -4..-2).should == "her"
- "hellö there".send(@method, -4...-2).should == "he"
- "hellö there".send(@method, 5..-1).should == " there"
- "hellö there".send(@method, 5...-1).should == " ther"
+ "hellö there".slice!(1..1).should == "e"
+ "hellö there".slice!(1..3).should == "ell"
+ "hellö there".slice!(1...3).should == "el"
+ "hellö there".slice!(-4..-2).should == "her"
+ "hellö there".slice!(-4...-2).should == "he"
+ "hellö there".slice!(5..-1).should == " there"
+ "hellö there".slice!(5...-1).should == " ther"
end
end
@@ -307,8 +307,8 @@ describe "String#slice! with Regexp" do
with_feature :encoding do
it "returns the matching portion of self with a multi byte character" do
- "hëllo there".send(@method, /[ë](.)\1/).should == "ëll"
- "".send(@method, //).should == ""
+ "hëllo there".slice!(/[ë](.)\1/).should == "ëll"
+ "".slice!(//).should == ""
end
end
@@ -391,13 +391,13 @@ describe "String#slice! with Regexp, index" do
with_feature :encoding do
it "returns the encoding aware capture for the given index" do
- "hår".send(@method, /(.)(.)(.)/, 0).should == "hår"
- "hår".send(@method, /(.)(.)(.)/, 1).should == "h"
- "hår".send(@method, /(.)(.)(.)/, 2).should == "å"
- "hår".send(@method, /(.)(.)(.)/, 3).should == "r"
- "hår".send(@method, /(.)(.)(.)/, -1).should == "r"
- "hår".send(@method, /(.)(.)(.)/, -2).should == "å"
- "hår".send(@method, /(.)(.)(.)/, -3).should == "h"
+ "hår".slice!(/(.)(.)(.)/, 0).should == "hår"
+ "hår".slice!(/(.)(.)(.)/, 1).should == "h"
+ "hår".slice!(/(.)(.)(.)/, 2).should == "å"
+ "hår".slice!(/(.)(.)(.)/, 3).should == "r"
+ "hår".slice!(/(.)(.)(.)/, -1).should == "r"
+ "hår".slice!(/(.)(.)(.)/, -2).should == "å"
+ "hår".slice!(/(.)(.)(.)/, -3).should == "h"
end
end
diff --git a/spec/ruby/core/string/split_spec.rb b/spec/ruby/core/string/split_spec.rb
index 0d2c6211c4..b89a28c149 100644
--- a/spec/ruby/core/string/split_spec.rb
+++ b/spec/ruby/core/string/split_spec.rb
@@ -402,4 +402,14 @@ describe "String#split with Regexp" do
broken_str.force_encoding('utf-8')
lambda{ broken_str.split(/\r\n|\r|\n/) }.should raise_error(ArgumentError)
end
+
+ ruby_version_is "2.6" do
+ it "yields each split substrings if a block is given" do
+ a = []
+ returned_object = "chunky bacon".split(" ") { |str| a << str.capitalize }
+
+ returned_object.should == "chunky bacon"
+ a.should == ["Chunky", "Bacon"]
+ end
+ end
end
diff --git a/spec/ruby/core/string/unpack/a_spec.rb b/spec/ruby/core/string/unpack/a_spec.rb
index 0adcf0ff80..3de338e2e1 100644
--- a/spec/ruby/core/string/unpack/a_spec.rb
+++ b/spec/ruby/core/string/unpack/a_spec.rb
@@ -3,12 +3,14 @@ require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
require_relative 'shared/string'
+require_relative 'shared/taint'
describe "String#unpack with format 'A'" do
it_behaves_like :string_unpack_basic, 'A'
it_behaves_like :string_unpack_no_platform, 'A'
it_behaves_like :string_unpack_string, 'A'
it_behaves_like :string_unpack_Aa, 'A'
+ it_behaves_like :string_unpack_taint, 'A'
it "removes trailing space and NULL bytes from the decoded string" do
[ ["a\x00 b \x00", ["a\x00 b", ""]],
@@ -40,6 +42,7 @@ describe "String#unpack with format 'a'" do
it_behaves_like :string_unpack_no_platform, 'a'
it_behaves_like :string_unpack_string, 'a'
it_behaves_like :string_unpack_Aa, 'a'
+ it_behaves_like :string_unpack_taint, 'a'
it "does not remove trailing whitespace or NULL bytes from the decoded string" do
[ ["a\x00 b \x00", ["a\x00 b \x00"]],
diff --git a/spec/ruby/core/string/unpack/b_spec.rb b/spec/ruby/core/string/unpack/b_spec.rb
index 332c85b5f8..a0bbc3d421 100644
--- a/spec/ruby/core/string/unpack/b_spec.rb
+++ b/spec/ruby/core/string/unpack/b_spec.rb
@@ -2,10 +2,12 @@
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
+require_relative 'shared/taint'
describe "String#unpack with format 'B'" do
it_behaves_like :string_unpack_basic, 'B'
it_behaves_like :string_unpack_no_platform, 'B'
+ it_behaves_like :string_unpack_taint, 'B'
it "decodes one bit from each byte for each format character starting with the most significant bit" do
[ ["\x00", "B", ["0"]],
@@ -96,6 +98,7 @@ end
describe "String#unpack with format 'b'" do
it_behaves_like :string_unpack_basic, 'b'
it_behaves_like :string_unpack_no_platform, 'b'
+ it_behaves_like :string_unpack_taint, 'b'
it "decodes one bit from each byte for each format character starting with the least significant bit" do
[ ["\x00", "b", ["0"]],
diff --git a/spec/ruby/core/string/unpack/h_spec.rb b/spec/ruby/core/string/unpack/h_spec.rb
index 7d0acf5718..07d52149d1 100644
--- a/spec/ruby/core/string/unpack/h_spec.rb
+++ b/spec/ruby/core/string/unpack/h_spec.rb
@@ -2,10 +2,12 @@
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
+require_relative 'shared/taint'
describe "String#unpack with format 'H'" do
it_behaves_like :string_unpack_basic, 'H'
it_behaves_like :string_unpack_no_platform, 'H'
+ it_behaves_like :string_unpack_taint, 'H'
it "decodes one nibble from each byte for each format character starting with the most significant bit" do
[ ["\x8f", "H", ["8"]],
@@ -66,6 +68,7 @@ end
describe "String#unpack with format 'h'" do
it_behaves_like :string_unpack_basic, 'h'
it_behaves_like :string_unpack_no_platform, 'h'
+ it_behaves_like :string_unpack_taint, 'h'
it "decodes one nibble from each byte for each format character starting with the least significant bit" do
[ ["\x8f", "h", ["f"]],
diff --git a/spec/ruby/core/string/unpack/m_spec.rb b/spec/ruby/core/string/unpack/m_spec.rb
index 0ae1118583..d714f6fbcb 100644
--- a/spec/ruby/core/string/unpack/m_spec.rb
+++ b/spec/ruby/core/string/unpack/m_spec.rb
@@ -2,10 +2,12 @@
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
+require_relative 'shared/taint'
describe "String#unpack with format 'M'" do
it_behaves_like :string_unpack_basic, 'M'
it_behaves_like :string_unpack_no_platform, 'M'
+ it_behaves_like :string_unpack_taint, 'M'
it "decodes an empty string" do
"".unpack("M").should == [""]
@@ -100,6 +102,7 @@ end
describe "String#unpack with format 'm'" do
it_behaves_like :string_unpack_basic, 'm'
it_behaves_like :string_unpack_no_platform, 'm'
+ it_behaves_like :string_unpack_taint, 'm'
it "decodes an empty string" do
"".unpack("m").should == [""]
diff --git a/spec/ruby/core/string/unpack/p_spec.rb b/spec/ruby/core/string/unpack/p_spec.rb
index 57b51fef00..136e32adfd 100644
--- a/spec/ruby/core/string/unpack/p_spec.rb
+++ b/spec/ruby/core/string/unpack/p_spec.rb
@@ -1,21 +1,52 @@
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
+require_relative 'shared/taint'
describe "String#unpack with format 'P'" do
it_behaves_like :string_unpack_basic, 'P'
+ it_behaves_like :string_unpack_taint, 'P'
- it "returns a random object after consuming a size-of a machine word bytes" do
- str = "\0" * 1.size
- str.unpack("P").should be_kind_of(Object)
+ it "round-trips a string through pack and unpack" do
+ ["hello"].pack("P").unpack("P5").should == ["hello"]
+ end
+
+ it "cannot unpack a string except from the same object that created it, or a duplicate of it" do
+ packed = ["hello"].pack("P")
+ packed.unpack("P5").should == ["hello"]
+ packed.dup.unpack("P5").should == ["hello"]
+ lambda { packed.to_sym.to_s.unpack("P5") }.should raise_error(ArgumentError, /no associated pointer/)
+ end
+
+ it "taints the unpacked string" do
+ ["hello"].pack("P").unpack("P5").first.tainted?.should be_true
+ end
+
+ it "reads as many characters as specified" do
+ ["hello"].pack("P").unpack("P1").should == ["h"]
+ end
+
+ it "reads only as far as a NUL character" do
+ ["hello"].pack("P").unpack("P10").should == ["hello"]
end
end
describe "String#unpack with format 'p'" do
it_behaves_like :string_unpack_basic, 'p'
+ it_behaves_like :string_unpack_taint, 'p'
+
+ it "round-trips a string through pack and unpack" do
+ ["hello"].pack("p").unpack("p").should == ["hello"]
+ end
+
+ it "cannot unpack a string except from the same object that created it, or a duplicate of it" do
+ packed = ["hello"].pack("p")
+ packed.unpack("p").should == ["hello"]
+ packed.dup.unpack("p").should == ["hello"]
+ lambda { packed.to_sym.to_s.unpack("p") }.should raise_error(ArgumentError, /no associated pointer/)
+ end
- it "returns a random object after consuming a size-of a machine word bytes" do
- str = "\0" * 1.size
- str.unpack("p").should be_kind_of(Object)
+ it "taints the unpacked string" do
+ ["hello"].pack("p").unpack("p").first.tainted?.should be_true
end
end
diff --git a/spec/ruby/core/string/unpack/shared/taint.rb b/spec/ruby/core/string/unpack/shared/taint.rb
new file mode 100644
index 0000000000..391338192a
--- /dev/null
+++ b/spec/ruby/core/string/unpack/shared/taint.rb
@@ -0,0 +1,81 @@
+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/u_spec.rb b/spec/ruby/core/string/unpack/u_spec.rb
index 6326bd7963..ee1d6c68e7 100644
--- a/spec/ruby/core/string/unpack/u_spec.rb
+++ b/spec/ruby/core/string/unpack/u_spec.rb
@@ -3,11 +3,13 @@ require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
require_relative 'shared/unicode'
+require_relative 'shared/taint'
describe "String#unpack with format 'U'" do
it_behaves_like :string_unpack_basic, 'U'
it_behaves_like :string_unpack_no_platform, 'U'
it_behaves_like :string_unpack_unicode, 'U'
+ it_behaves_like :string_unpack_taint, 'U'
it "raises ArgumentError on a malformed byte sequence" do
lambda { "\xE3".unpack('U') }.should raise_error(ArgumentError)
@@ -21,6 +23,7 @@ end
describe "String#unpack with format 'u'" do
it_behaves_like :string_unpack_basic, 'u'
it_behaves_like :string_unpack_no_platform, 'u'
+ it_behaves_like :string_unpack_taint, 'u'
it "decodes an empty string as an empty string" do
"".unpack("u").should == [""]
diff --git a/spec/ruby/core/string/unpack/z_spec.rb b/spec/ruby/core/string/unpack/z_spec.rb
index 67d36ac8bf..2de624a74d 100644
--- a/spec/ruby/core/string/unpack/z_spec.rb
+++ b/spec/ruby/core/string/unpack/z_spec.rb
@@ -3,11 +3,13 @@ require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
require_relative 'shared/string'
+require_relative 'shared/taint'
describe "String#unpack with format 'Z'" do
it_behaves_like :string_unpack_basic, 'Z'
it_behaves_like :string_unpack_no_platform, 'Z'
it_behaves_like :string_unpack_string, 'Z'
+ it_behaves_like :string_unpack_taint, 'Z'
it "stops decoding at NULL bytes when passed the '*' modifier" do
"a\x00\x00 b \x00c".unpack('Z*Z*Z*Z*').should == ["a", "", " b ", "c"]