Skip to content

Commit 9a7fda9

Browse files
committed
[GR-18163] Fix Array#pack with x* to not output null characters
PullRequest: truffleruby/3221
2 parents 2dd0262 + d8691a5 commit 9a7fda9

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Bug fixes:
1616
* `SIGINT`/`Interrupt`/`Ctrl+C` now shows the backtrace and exits as signaled, like CRuby (@eregon).
1717
* Update patch feature finding to prefer the longest matching load path (#2605, @bjfish).
1818
* Fix `Hash#{to_s,inspect}` for keys whose `#inspect` return a frozen String (#2613, @eregon).
19+
* Fix `Array#pack` with `x*` to not output null characters (#2614, @bjfish).
1920

2021
Compatibility:
2122

spec/ruby/core/array/pack/x_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
it "does not add a NULL byte when passed the '*' modifier" do
3232
[].pack("x*").should == ""
33+
[1, 2].pack("Cx*C").should == "\x01\x02"
3334
end
3435
end
3536

src/main/java/org/truffleruby/core/format/pack/SimplePackTreeBuilder.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,12 @@ public void back(int count) {
235235

236236
@Override
237237
public void nullByte(int count) {
238-
appendNode((sharedTreeBuilder.applyCount(
239-
count,
240-
WriteByteNodeGen.create(
241-
new LiteralFormatNode((byte) 0)))));
238+
if (count != SimplePackParser.COUNT_STAR) {
239+
appendNode((sharedTreeBuilder.applyCount(
240+
count,
241+
WriteByteNodeGen.create(
242+
new LiteralFormatNode((byte) 0)))));
243+
}
242244
}
243245

244246
@Override

0 commit comments

Comments
 (0)