From ebb0996cfc7fbb6d5f962671b2d92a3773e2ec25 Mon Sep 17 00:00:00 2001 From: Sebastian Stock <42280794+sostock@users.noreply.github.com> Date: Fri, 7 Aug 2020 11:17:31 +0200 Subject: [PATCH] Fix replace (#36953) --- base/strings/util.jl | 2 +- test/strings/util.jl | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/base/strings/util.jl b/base/strings/util.jl index 934c8e902de86..e1e566568d11a 100644 --- a/base/strings/util.jl +++ b/base/strings/util.jl @@ -521,7 +521,7 @@ function replace(str::String, pat_repl::Pair; count::Integer=typemax(Int)) i = k = nextind(str, k) end r = something(findnext(pattern,str,k), 0) - r == 0:-1 || n == count && break + r === 0:-1 || n == count && break j, k = first(r), last(r) n += 1 end diff --git a/test/strings/util.jl b/test/strings/util.jl index 59024e972021b..7a144e3c35000 100644 --- a/test/strings/util.jl +++ b/test/strings/util.jl @@ -297,6 +297,9 @@ end @test replace("a", in("a") => typeof) == "Char" @test replace("a", ['a'] => typeof) == "Char" + # Issue 36953 + @test replace("abc", "" => "_", count=1) == "_abc" + end @testset "chomp/chop" begin