Skip to content

Commit

Permalink
Fix :noshift construction of an empty SubString (JuliaLang#51923)
Browse files Browse the repository at this point in the history
  • Loading branch information
tecosaur committed Dec 30, 2023
1 parent 9deee46 commit 2091058
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/strings/substring.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct SubString{T<:AbstractString} <: AbstractString
return new(s, i-1, nextind(s,j)-i)
end
function SubString{T}(s::T, i::Int, j::Int, ::Val{:noshift}) where T<:AbstractString
@boundscheck begin
@boundscheck if !(i == j == 0)
si, sj = i + 1, prevind(s, j + i + 1)
@inbounds isvalid(s, si) || string_index_err(s, si)
@inbounds isvalid(s, sj) || string_index_err(s, sj)
Expand Down
6 changes: 6 additions & 0 deletions test/strings/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ end
@test (@views (x[3], x[1:2], x[[1,4]])) isa Tuple{Char, SubString, String}
@test (@views (x[3], x[1:2], x[[1,4]])) == ('c', "ab", "ad")
end

@testset ":noshift constructor" begin
@test SubString("", 0, 0, Val(:noshift)) == ""
@test SubString("abcd", 0, 1, Val(:noshift)) == "a"
@test SubString("abcd", 0, 4, Val(:noshift)) == "abcd"
end
end


Expand Down

0 comments on commit 2091058

Please sign in to comment.