Skip to content

Keep spaces in XDG user dir paths in the sandbox script - #3084

Merged
ivan-hc merged 1 commit into
ivan-hc:mainfrom
sagarrsharmaa:sandbox-xdg-dirs-with-spaces
Nov 27, 2026
Merged

ivan-hc merged 1 commit into
ivan-hc:mainfrom
sagarrsharmaa:sandbox-xdg-dirs-with-spaces

Conversation

@sagarrsharmaa

@sagarrsharmaa sagarrsharmaa commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

The XDG user dir loop used by --sandbox runs eval XDG_DIR="$(xdg-user-dir $DIR)", so the path is parsed again as shell code. When a dir's name has a space, the word after the space runs as a command and XDG_DIR keeps its previous value. The same loop is copied into the launcher script that replaces the AppImage.

  • With the pt_BR default Desktop, "Área de trabalho" (pt "Área de Trabalho", ru "Рабочий стол" and el "Επιφάνεια εργασίας" have spaces too):
    • AM prints de: command not found and asks Allow APP access to "~/Desktop"?.
    • Allowing it makes the launcher pass --add-file ~/Desktop:rw, a folder that doesn't exist, so the app never sees the real Desktop.
    • The launcher prints eval: de: not found every time the app starts.
  • A dir later in the loop gets the previous dir's path. With XDG_PICTURES_DIR="$HOME/My Pictures":
    • PICTURES becomes ~/Music, and the prompts ask about ~/Music twice.
    • Allowing Pictures gives the app read-write access to ~/Music.

xdg-user-dir already prints the full path, so a plain command substitution is enough. The second line uses eval "$DIR=\$XDG_DIR", as #3076 did for _read. Both loops get the same change, 4 lines in total, and both lines are POSIX sh. The dev branch has the same lines, and this applies there too.

How I tested it: I extracted AM's sandbox functions and ran them in an Ubuntu 24.04 container (bash 5.2, dash as /bin/sh). I used a user-dirs.dirs with the pt_BR names, and another with XDG_PICTURES_DIR="$HOME/My Pictures", plus a stand-in sas that prints the --add-file/--rm-file arguments the generated launcher passes. Before the change the launcher passes ~/Desktop:rw and ~/Music:rw. After it, the launcher passes "~/Área de trabalho":rw and "~/My Pictures":rw, and the not found errors are gone. Dirs without spaces give the same arguments as before. bash -n is clean, and shellcheck reports nothing new on install.am or the generated script. I did not run regress/test-am-sandbox.sh against a real aisap/sas install.

The loop that looks up the XDG user dirs for "--sandbox" runs
eval XDG_DIR="$(xdg-user-dir $DIR)", so the path is parsed again as
shell code. If a dir has a space in its name, the word after the space
is run as a command and XDG_DIR keeps whatever it held before:

- With the pt_BR default Desktop, "Área de trabalho" (Russian
  "Рабочий стол" and Greek have a space too), it prints
  "de: not found" and DESKTOP falls back to ~/Desktop, which doesn't
  exist. Allowing the app to access the Desktop gives it
  --add-file ~/Desktop:rw instead of the real folder.
- A dir later in the loop gets the previous dir's path. With
  XDG_PICTURES_DIR="$HOME/My Pictures", PICTURES becomes ~/Music, so
  the prompts ask about ~/Music twice and allowing Pictures gives the
  app read-write access to ~/Music.

The same loop is in the launcher script that replaces the AppImage, so
the error is printed every time the sandboxed app starts. The second
line, eval $DIR="$XDG_DIR", would split the path the same way once
the first one is fixed.

xdg-user-dir already prints the full path, so a plain command
substitution is enough, and eval "$DIR=\$XDG_DIR" (as 7d957c4 did for
_read) assigns the value without parsing it again. Both work in POSIX
sh.
@ivan-hc

ivan-hc commented Nov 27, 2026

Copy link
Copy Markdown
Owner

@Samueru-sama please review this.

NOTE, changes to --sandbox are coming in the dev branch of this repository. See #3070

@Samueru-sama

Copy link
Copy Markdown
Contributor

lgtm

@sagarrsharmaa

Copy link
Copy Markdown
Contributor Author

Thanks for the review! The dev branch still has the same two lines (modules/install.am lines 931 and 1074), and this fix applies there cleanly. Happy to open the same change against dev if that's easier with #3070.

@ivan-hc

ivan-hc commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Thanks for the review! The dev branch still has the same two lines (modules/install.am lines 931 and 1074), and this fix applies there cleanly. Happy to open the same change against dev if that's easier with #3070.

No problem, I will keep dev in sync with main as always. Thanks.

@ivan-hc
ivan-hc merged commit ca92041 into ivan-hc:main Nov 27, 2026
@ivan-hc

ivan-hc commented Nov 27, 2026

Copy link
Copy Markdown
Owner

No problem, I will keep dev in sync with main as always. Thanks.

done #3085

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

Successfully merging this pull request may close these issues.

3 participants