diff --git a/spec/std/string_spec.cr b/spec/std/string_spec.cr index 6fbdebc7d0ce..13a07e03148f 100644 --- a/spec/std/string_spec.cr +++ b/spec/std/string_spec.cr @@ -1718,6 +1718,8 @@ describe "String" do "hello".tr("helo", "1212").should eq("12112") "this".tr("this", "ⓧ").should eq("ⓧⓧⓧⓧ") "über".tr("ü", "u").should eq("uber") + "aabbcc".tr("a", "xyz").should eq("xxbbcc") + "aabbcc".tr("a", "いろは").should eq("いいbbcc") end context "given no replacement characters" do diff --git a/src/string.cr b/src/string.cr index cc84d26345f9..fffebaad4095 100644 --- a/src/string.cr +++ b/src/string.cr @@ -1591,7 +1591,7 @@ class String return delete(from) if to.empty? if from.bytesize == 1 - return gsub(from.unsafe_byte_at(0).unsafe_chr, to) + return gsub(from.unsafe_byte_at(0).unsafe_chr, to[0]) end multi = nil