Skip to content

Commit

Permalink
Fix for reverse search, fixes JuliaLang#39401, fixes JuliaLang#40244(J…
Browse files Browse the repository at this point in the history
  • Loading branch information
Moelf authored and johanmon committed Jul 5, 2021
1 parent 608a698 commit 5ba05c6
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/strings/search.jl
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ function _rsearchindex(s::AbstractVector{<:Union{Int8,UInt8}}, t::AbstractVector
n = length(t)
m = length(s)
k = Int(_k) - sentinel
k < 1 && throw(BoundsError(s, _k))
k < 0 && throw(BoundsError(s, _k))

if n == 0
return 0 <= k <= m ? max(k, 1) : sentinel
Expand Down
2 changes: 2 additions & 0 deletions test/strings/search.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ for str in [astr]
@test findprev('l', str, 2) == nothing
@test findlast(',', str) == 6
@test findprev(',', str, 5) == nothing
@test findlast(str, "") == nothing
@test findlast(str^2, str) == nothing
@test findlast('\n', str) == 14
end

Expand Down
1 change: 1 addition & 0 deletions test/strings/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ end
@test split("", "") == rsplit("", "") == [""]
@test split("abc", "") == rsplit("abc", "") == ["a","b","c"]
@test rsplit("abc", "", limit=2) == ["ab","c"]
@test rsplit("", "//") == [""]
@test split("abc", "", limit=2) == ["a","bc"]

@test split("", r"") == [""]
Expand Down

0 comments on commit 5ba05c6

Please sign in to comment.