fix: ignore empty or relative XDG base directory variables - #3833
Open
M1lan wants to merge 1 commit into
Open
Conversation
Per the XDG Base Directory Specification, XDG_CONFIG_HOME, XDG_DATA_HOME and XDG_RUNTIME_DIR values that are empty or not absolute paths are invalid and must be ignored, falling back to the defaults. Previously an empty XDG_CONFIG_HOME made config_dir() return the relative path "atuin", and Settings::get_config_path() would then create a stray ./atuin directory in whatever cwd the process happened to run from.
Contributor
Greptile SummaryFixes XDG base-directory handling by ignoring empty or relative environment values.
Confidence Score: 5/5The PR appears safe to merge. The changed directory functions reject invalid XDG values while retaining existing behavior for valid absolute paths and unset variables. Important Files Changed
Reviews (1): Last reviewed commit: "fix: ignore empty or relative XDG base d..." | Re-trigger Greptile |
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
config_dir(),data_dir()andruntime_dir()inatuin-commonuse the raw value ofXDG_CONFIG_HOME/XDG_DATA_HOME/XDG_RUNTIME_DIRwithout validating it. The XDG Base Directory Specification requires that empty or non-absolute values be ignored.With
XDG_CONFIG_HOMEset but empty,config_dir()returns the relative pathatuin, andSettings::get_config_path()thencreate_dir_all()s it — leaving a stray empty./atuindirectory in whatever cwd the process ran from.Reproduce:
Fix
Shared
xdg_dir()helper: use the env var only when it parses to an absolute path, otherwise fall back to the spec default. Applied toconfig_dir(),data_dir()andruntime_dir().Unit tests added for the empty and relative cases (wired into the existing sequential
test_dirsrunner).