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

At Ubuntu installed by Japanese locale setting, the error occurs #6

Closed
ujimushi opened this issue Feb 17, 2024 · 1 comment
Closed

Comments

@ujimushi
Copy link

When I tried PlutoPlotly, Error was occured like next.

julia> using PlutoPlotly
Precompiling PlutoPlotly
         Info Given PlutoPlotly was explicitly requested, output will be shown live 
ERROR: LoadError: InitError: StringIndexError: invalid index [41], valid nearby indices [39]=>'', [42]=>'\"'
Stacktrace:
  [1] string_index_err(s::String, i::Int64)
    @ Base ./strings/string.jl:12
   [2] SubString{String}(s::String, i::Int64, j::Int64)
    @ Base ./strings/substring.jl:35
  [3] SubString
    @ ./strings/substring.jl:41 [inlined]
  [4] SubString
    @ ./strings/substring.jl:47 [inlined]
  [5] SubString
    @ ./strings/substring.jl:43 [inlined]
  [6] getindex
    @ ./strings/substring.jl:292 [inlined]
  [7] parseuserdirs(configdir::String)
    @ BaseDirs ~/.julia/packages/BaseDirs/tgw06/src/unix.jl:23
  [8] reload()
    @ BaseDirs ~/.julia/packages/BaseDirs/tgw06/src/unix.jl:56
  [9] __init__()
    @ BaseDirs ~/.julia/packages/BaseDirs/tgw06/src/BaseDirs.jl:38

I found the error unix.jl:23 of BaseDirs.jl.
I am using Ubuntu 23.10 installed with Japanese locale.
Default ~/.config/user-dirs.dirs is like next at Japanese locale.

# This file is written by xdg-user-dirs-update
# If you want to change or add directories, just edit the line you're
# interested in. All local changes will be retained on the next run.
# Format is XDG_xxx_DIR="$HOME/yyy", where yyy is a shell-escaped
# homedir-relative path, or XDG_xxx_DIR="/yyy", where /yyy is an
# absolute path. No other format is supported.
# 
XDG_DESKTOP_DIR="$HOME/デスクトップ"
XDG_DOWNLOAD_DIR="$HOME/ダウンロード"
XDG_TEMPLATES_DIR="$HOME/テンプレート"
XDG_PUBLICSHARE_DIR="$HOME/公開"
XDG_DOCUMENTS_DIR="$HOME/ドキュメント"
XDG_MUSIC_DIR="$HOME/ミュージック"
XDG_PICTURES_DIR="$HOME/ピクチャ"
XDG_VIDEOS_DIR="$HOME/ビデオ"

The cause of the error is the value[2:end-1] part.
I tried to reproduce the error with REPL, next.

julia> line="XDG_DESKTOP_DIR=\"\$HOME/デスクトップ\""
"XDG_DESKTOP_DIR=\"\$HOME/デスクトップ\""

julia> key, value = split(line, '=', limit=2)
2-element Vector{SubString{String}}:
 "XDG_DESKTOP_DIR"
 "\"\$HOME/デスクトップ\""

julia> value[2:end-1]
ERROR: StringIndexError: invalid index [41], valid nearby indices [39]=>'', [42]=>'\"'
Stacktrace:
 [1] string_index_err(s::String, i::Int64)
   @ Base ./strings/string.jl:12
 [2] SubString{String}(s::String, i::Int64, j::Int64)
   @ Base ./strings/substring.jl:35
 [3] SubString
   @ ./strings/substring.jl:41 [inlined]
 [4] SubString
   @ ./strings/substring.jl:47 [inlined]
 [5] SubString
   @ ./strings/substring.jl:43 [inlined]
 [6] getindex(s::SubString{String}, r::UnitRange{Int64})
   @ Base ./strings/substring.jl:292
 [7] top-level scope
   @ REPL[4]:1

An error occurs when accessing the second and subsequent bytes of a multibyte character using index.

The fixes I can think of are
replace(value, r"^\"" => "", r"\"$" =>"")
or
strip(value, '"').

julia> replace(value, r"^\"" => "", r"\"$" => "")
"\$HOME/デスクトップ"

julia> strip(value, '"')
"\$HOME/デスクトップ"

In environments without Japanese fonts, the characters may not be visible. Sorry.

@tecosaur
Copy link
Owner

Thanks for both raising this issue ujimushi and doing such a thorough investigation into the root cause, this is tremendously helpful! 😀

I've just fixed this, and gone a step further and looked for any other instances of offset-based string indexing like this that could cause a similar problem. I've found a few others, and fixed them too. I've also added a new testset based on the details you've so kindly provided here. See 742caa3.

I'll release a patch version (probably v1.2.3) shortly 🙂.

Thanks again!

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

2 participants