Skip to content

Commit

Permalink
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions spec/std/string_spec.cr
Original file line number Diff line number Diff line change
@@ -845,6 +845,10 @@ describe "String" do
"fここ bここr bここここz".sub("ここ", "そこ").should eq("fそこ bここr bここここz")
end

it "subs with string and string (#3258)" do
"私は日本人です".sub("日本", "スペイン").should eq("私はスペイン人です")
end

it "subs with string and block" do
result = "foo boo".sub("oo") { |value|
value.should eq("oo")
2 changes: 1 addition & 1 deletion src/string.cr
Original file line number Diff line number Diff line change
@@ -1366,7 +1366,7 @@ class String
# "hello yellow".sub("ll") { "dd" } # => "heddo yellow"
# ```
def sub(string : String, &block)
index = self.index(string)
index = self.byte_index(string)
return self unless index

String.build(bytesize) do |buffer|

0 comments on commit 8bd15bc

Please sign in to comment.