Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rsplit error on empty strings #40244

Closed
elbrook33 opened this issue Mar 28, 2021 · 5 comments
Closed

rsplit error on empty strings #40244

elbrook33 opened this issue Mar 28, 2021 · 5 comments

Comments

@elbrook33
Copy link

Hi, in case it's unintentional, rsplit gives me an error for empty strings in 1.6, it used to give [""]. Thanks!

@bicycle1885
Copy link
Member

Hi, can you show us a minimal example?

@elbrook33
Copy link
Author

elbrook33 commented Mar 29, 2021 via email

@bicycle1885
Copy link
Member

Thank you. I can reproduce the problem now.

Julia 1.5.4:

julia> rsplit("", "//")
1-element Array{SubString{String},1}:
 ""

Julia 1.6.0:

julia> rsplit("", "//")
ERROR: BoundsError: attempt to access 0-element Vector{UInt8} at index [0]
Stacktrace:
 [1] _rsearchindex(s::Vector{UInt8}, t::Vector{UInt8}, _k::Int64)
   @ Base ./strings/search.jl:461
 [2] _rsearchindex(s::String, t::String, i::Int64)
   @ Base ./strings/search.jl:446
 [3] _rsearch
   @ ./strings/search.jl:523 [inlined]
 [4] findprev
   @ ./strings/search.jl:556 [inlined]
 [5] findlast
   @ ./strings/search.jl:363 [inlined]
 [6] _rsplit(str::String, splitter::String, limit::Int64, keepempty::Bool, strs::Vector{SubString{String}})
   @ Base ./strings/util.jl:492
 [7] #rsplit#377
   @ ./strings/util.jl:479 [inlined]
 [8] rsplit(str::String, splitter::String)
   @ Base ./strings/util.jl:479
 [9] top-level scope
   @ REPL[6]:1

@reallyasi9
Copy link

reallyasi9 commented Jun 11, 2021

For an additional data point, the same error results from attempting an rsplit where the first characters of the string match the split pattern:

julia> versioninfo()
Julia Version 1.6.1
Commit 6aaedecc44 (2021-04-23 05:59 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, skylake)

julia> rsplit("hello", "he")
ERROR: BoundsError: attempt to access 5-element Vector{UInt8} at index [0]
Stacktrace:
 [1] _rsearchindex(s::Vector{UInt8}, t::Vector{UInt8}, _k::Int64)
   @ Base .\strings\search.jl:461
 [2] _rsearchindex(s::String, t::String, i::Int64)
   @ Base .\strings\search.jl:446
 [3] _rsearch
   @ .\strings\search.jl:523 [inlined]
 [4] findprev
   @ .\strings\search.jl:556 [inlined]
 [5] _rsplit(str::String, splitter::String, limit::Int64, keepempty::Bool, strs::Vector{SubString{String}})
   @ Base .\strings\util.jl:497
 [6] #rsplit#377
   @ .\strings\util.jl:479 [inlined]
 [7] rsplit(str::String, splitter::String)
   @ Base .\strings\util.jl:479
 [8] top-level scope
   @ REPL[3]:1

But matching a single character works:

julia> rsplit("hello", "h")
2-element Vector{SubString{String}}:
 ""
 "ello"

And split works:

julia> split("hello", "lo")
2-element Vector{SubString{String}}:
 "hel"
 ""

@KristofferC
Copy link
Member

I think this is the same as #39401. cc @Moelf

KristofferC pushed a commit that referenced this issue Jun 17, 2021
KristofferC pushed a commit that referenced this issue Jun 29, 2021
staticfloat pushed a commit that referenced this issue Dec 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants