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 @@ -8,6 +8,7 @@ Bug fixes:
8
8
* Fix error message when the method name is not a Symbol or String for ` Kernel#respond_to? ` (#2132 , @ssnickolay )
9
9
* Fixed setting of special variables in enumerators and enumerables (#1484 ).
10
10
* Fix status and output when SystemExit is subclassed and raised (#2128 )
11
+ * Fix ` String#{chomp, chomp!} ` issue with invalid encoded strings (#2133 ).
11
12
12
13
Compatibility:
13
14
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 @@ -826,7 +826,7 @@ def chomp!(sep=undefined)
826
826
if j = Primitive . string_previous_byte_index ( self , bytes )
827
827
chr = Primitive . string_chr_at ( self , j )
828
828
829
- if chr . ord == 13
829
+ if ! Primitive . nil? ( chr ) && chr . ord == 13
830
830
bytes = j
831
831
end
832
832
end
@@ -839,13 +839,13 @@ def chomp!(sep=undefined)
839
839
840
840
while i = Primitive . string_previous_byte_index ( self , bytes )
841
841
chr = Primitive . string_chr_at ( self , i )
842
- break unless chr . ord == 10
842
+ break unless ! Primitive . nil? ( chr ) && chr . ord == 10
843
843
844
844
bytes = i
845
845
846
846
if j = Primitive . string_previous_byte_index ( self , i )
847
847
chr = Primitive . string_chr_at ( self , j )
848
- if chr . ord == 13
848
+ if ! Primitive . nil? ( chr ) && chr . ord == 13
849
849
bytes = j
850
850
end
851
851
end
You can’t perform that action at this time.
0 commit comments