fix(layouts): keep literal paths when shellexpand fails#5386
Open
arimu1 wants to merge 1 commit into
Open
Conversation
A cwd/command/edit path containing a literal `$` that isn't a real environment variable (eg. a directory named `$programId+`) made shellexpand::full() return an Err, which parse_path() turned into a hard ConfigError, failing the whole layout parse. This is especially bad for resurrection layouts: zellij serializes a pane's real cwd verbatim into session-layout.kdl, so a directory name with a literal `$` produces a cache file that zellij itself can no longer parse, and `zellij attach` fails with a generic error. Fall back to the original, unexpanded string when shellexpand fails instead of aborting the parse, matching the existing fallback pattern already used for plugin path expansion in RunPluginLocation::parse. Fixes zellij-org#5378
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Fixes #5378
Layout parsing runs
shellexpand::full()on everycwd/command/editpath string (KdlLayoutParser::parse_pathinzellij-utils/src/kdl/kdl_layout_parser.rs). If that string contains a literal$that doesn't happen to name a real environment variable (e.g. a directory called$programId+, as produced by React Router / Remix file-based routing),shellexpand::fullreturns anErr, whichparse_pathturns into a hardConfigError- aborting the whole layout parse.This is especially bad for resurrection layouts: zellij writes a pane's real, unescaped
cwdverbatim intosession-layout.kdl. If that cwd contains a literal$, the cache file zellij just wrote becomes unparseable by zellij itself, andzellij attachfails with only a generic error (Failed to parse resurrection layout file ...: KdlDeserialization error: Failed to parse Zellij configuration.), hiding the real cause.Minimal repro (from the issue):
fails with:
Fix
parse_pathnow falls back to the original, unexpanded string whenshellexpand::fullerrors, instead of propagating aConfigError. Alog::warn!is emitted so the fallback is still visible for debugging. Legitimate expansion (~, real$VARS) is unaffected - only the error case falls back to the raw string.This mirrors the fallback pattern already used for plugin path expansion in
RunPluginLocation::parse(zellij-utils/src/input/layout.rs), so it's consistent with existing conventions in this codebase.Testing
env_var_missing(zellij-utils/src/input/unit/layout_test.rs) to reflect the new behavior: a missing/unresolvable$VARno longer hard-fails layout parsing, it falls back to the literal string.literal_dollar_sign_in_cwd_is_not_a_parse_error, a regression test using the exact repro from the issue (pane command="ls" cwd="/tmp/foo/$programId+"), asserting the layout parses and the pane'scwdis kept as the literal/tmp/foo/$programId+.zellij-utilsunit test suite:409 passed; 0 failed; 2 ignored(thecli::testsmodule was skipped because several of its tests stack-overflow on this machine/toolchain independent of this change - reproduced identically on unmodifiedmain).cargo fmt -p zellij-utils -- --checkis clean.Note
I did not change how resurrection layouts are serialized (e.g. escaping
$as$$when writing). The parser-side fallback fixes the actual symptom (an unparseable file zellij wrote itself) without needing to touch the writer, and keeps existing hand-written layouts with a genuinely-missing env var loading instead of hard-failing, which seems like the more robust behavior for a value that's just going to become a path string either way.