Skip to content

Commit dba8426

Browse files
Th3-M4jorandrykonchin
authored andcommitted
raise ArgumentError on unknown directive Array pack/ String unpack
1 parent 8d6a8c0 commit dba8426

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

core/array/pack/shared/basic.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@
5757
# NOTE: Added this case just to not forget about the decision in the ticket
5858
it "raise ArgumentError when a directive is unknown" do
5959
# additional directive ('a') is required for the X directive
60-
-> { [@obj, @obj].pack("a R" + pack_format) }.should raise_error(ArgumentError)
61-
-> { [@obj, @obj].pack("a 0" + pack_format) }.should raise_error(ArgumentError)
62-
-> { [@obj, @obj].pack("a :" + pack_format) }.should raise_error(ArgumentError)
60+
-> { [@obj, @obj].pack("a R" + pack_format) }.should raise_error(ArgumentError, /unknown pack directive 'R'/)
61+
-> { [@obj, @obj].pack("a 0" + pack_format) }.should raise_error(ArgumentError, /unknown pack directive '0'/)
62+
-> { [@obj, @obj].pack("a :" + pack_format) }.should raise_error(ArgumentError, /unknown pack directive ':'/)
6363
end
6464
end
6565

core/string/unpack/shared/basic.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88
d.should_receive(:to_str).and_return("a"+unpack_format)
99
"abc".unpack(d).should be_an_instance_of(Array)
1010
end
11+
12+
ruby_version_is "3.3" do
13+
# https://bugs.ruby-lang.org/issues/19150
14+
it 'raise ArgumentError when a directive is unknown' do
15+
-> { "abcdefgh".unpack("a R" + unpack_format) }.should raise_error(ArgumentError, /unknown unpack directive 'R'/)
16+
-> { "abcdefgh".unpack("a 0" + unpack_format) }.should raise_error(ArgumentError, /unknown unpack directive '0'/)
17+
-> { "abcdefgh".unpack("a :" + unpack_format) }.should raise_error(ArgumentError, /unknown unpack directive ':'/)
18+
end
19+
end
1120
end
1221

1322
describe :string_unpack_no_platform, shared: true do

0 commit comments

Comments
 (0)