Skip to content

Commit 66fe51f

Browse files
Throw clearer ArgumentError for strip with two string args (#51491)
1 parent 2d93567 commit 66fe51f

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

base/strings/util.jl

+4
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ function lstrip(f, s::AbstractString)
369369
end
370370
lstrip(s::AbstractString) = lstrip(isspace, s)
371371
lstrip(s::AbstractString, chars::Chars) = lstrip(in(chars), s)
372+
lstrip(::AbstractString, ::AbstractString) = throw(ArgumentError("Both arguments are strings. The second argument should be a `Char` or collection of `Char`s"))
372373

373374
"""
374375
rstrip([pred=isspace,] str::AbstractString) -> SubString
@@ -402,6 +403,8 @@ function rstrip(f, s::AbstractString)
402403
end
403404
rstrip(s::AbstractString) = rstrip(isspace, s)
404405
rstrip(s::AbstractString, chars::Chars) = rstrip(in(chars), s)
406+
rstrip(::AbstractString, ::AbstractString) = throw(ArgumentError("Both arguments are strings. The second argument should be a `Char` or collection of `Char`s"))
407+
405408

406409
"""
407410
strip([pred=isspace,] str::AbstractString) -> SubString
@@ -429,6 +432,7 @@ julia> strip("{3, 5}\\n", ['{', '}', '\\n'])
429432
"""
430433
strip(s::AbstractString) = lstrip(rstrip(s))
431434
strip(s::AbstractString, chars::Chars) = lstrip(rstrip(s, chars), chars)
435+
strip(::AbstractString, ::AbstractString) = throw(ArgumentError("Both arguments are strings. The second argument should be a `Char` or collection of `Char`s"))
432436
strip(f, s::AbstractString) = lstrip(f, rstrip(f, s))
433437

434438
## string padding functions ##

test/strings/util.jl

+4
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ end
8989
@test rstrip(isnumeric, "abc0123") == "abc"
9090
@test lstrip("ello", ['e','o']) == "llo"
9191
@test rstrip("ello", ['e','o']) == "ell"
92+
93+
@test_throws ArgumentError strip("", "")
94+
@test_throws ArgumentError lstrip("", "")
95+
@test_throws ArgumentError rstrip("", "")
9296
end
9397

9498
@testset "partition" begin

0 commit comments

Comments
 (0)