Problems with strings which contain unicode characters on julia 0.7-DEV

Hi everyone! Is this a known issue on julia 0.7-DEV?

julia> str1 = "a "
"a "

julia> str2 = "a"
"a"

julia> str2 == str1[1:end-1]
true

julia> str1 = "₁ "
"₁ "

julia> str2 = "₁"
"₁"

julia> str2 == str1[1:end-1]
ERROR: UnicodeError: invalid character index
Stacktrace:
 [1] getindex(::String, ::UnitRange{Int64}) at ./strings/string.jl:292

My system is OS X 10.10.5; julia version is 0.7.0-DEV.2046 (commit 16139d0, 1 day old master). 0.6 doesn’t seem to have this problem.

Yes, it was decided to only allow valid codepoints in string indexing, use

str1[1:prevind(str1, end)]

It’s documented in the breaking changes section: https://github.com/JuliaLang/julia/blob/master/NEWS.md#breaking-changes

1 Like

Many thanks, @Keno!