File tree Expand file tree Collapse file tree 3 files changed +12
-3
lines changed
src/main/ruby/truffleruby/core Expand file tree Collapse file tree 3 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ Bug fixes:
20
20
* Fixed constant/identifier detection in lexer for non-ASCII encodings (#2079 , #2102 , @ivoanjo ).
21
21
* Fixed parsing of ` --jvm ` as an application argument (#2108 ).
22
22
* Fix ` rb_rescue2 ` to ignore the end marker ` (VALUE)0 ` (#2127 , #2130 ).
23
+ * Fix ` String#{chomp, chomp!} ` issue with invalid encoded strings (#2133 ).
23
24
24
25
Compatibility:
25
26
Original file line number Diff line number Diff line change 55
55
$/ = "cdef"
56
56
"abcdef" . chomp . should == "ab"
57
57
end
58
+
59
+ it "removes one trailing newline for string with invalid encoding" do
60
+ "\xa0 \xa1 \n " . chomp . should == "\xa0 \xa1 "
61
+ end
58
62
end
59
63
60
64
describe "when passed nil" do
108
112
it "returns an empty String when self is empty" do
109
113
"" . chomp ( "" ) . should == ""
110
114
end
115
+
116
+ it "removes one trailing newline for string with invalid encoding" do
117
+ "\xa0 \xa1 \n " . chomp ( "" ) . should == "\xa0 \xa1 "
118
+ end
111
119
end
112
120
113
121
describe "when passed '\\ n'" do
Original file line number Diff line number Diff line change @@ -844,7 +844,7 @@ def chomp!(sep=undefined)
844
844
if j = Primitive . string_previous_byte_index ( self , bytes )
845
845
chr = Primitive . string_chr_at ( self , j )
846
846
847
- if chr . ord == 13
847
+ if ! Primitive . nil? ( chr ) && chr . ord == 13
848
848
bytes = j
849
849
end
850
850
end
@@ -857,13 +857,13 @@ def chomp!(sep=undefined)
857
857
858
858
while i = Primitive . string_previous_byte_index ( self , bytes )
859
859
chr = Primitive . string_chr_at ( self , i )
860
- break unless chr . ord == 10
860
+ break unless ! Primitive . nil? ( chr ) && chr . ord == 10
861
861
862
862
bytes = i
863
863
864
864
if j = Primitive . string_previous_byte_index ( self , i )
865
865
chr = Primitive . string_chr_at ( self , j )
866
- if chr . ord == 13
866
+ if ! Primitive . nil? ( chr ) && chr . ord == 13
867
867
bytes = j
868
868
end
869
869
end
You can’t perform that action at this time.
0 commit comments