fix: source files using absolute paths for absolute BASH_SOURCE #1221
+159
−20
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.
Depending on the setup, we source the completion files with relative paths. This causes a problem when a completion script uses
BASH_SOURCE
to specify the helper script after the current working directory is changed. For example, with the following steps, the problem happens:This is because
_comp_cmd_make__extract_targets
(called by_comp_cmd_make
) usesBASH_SOURCE
to identify the location of the helper script, butBASH_SOURCE
contains a relative path from the directory where the completion file is first sourced.Full processing of .. in _comp_abspath
In the second commit 67e98c6, I modified
_comp_abspath
to properly handle..
. In the original implementation of_comp_abspath
, we just removed the beginning../
and..
in the middle path segments were left. In this PR, I changed_comp_abspath
to fully resolve..
. However, was there a reason to just remove..
? I initially thought it might be intended to prevent directory traversing, but it didn't work for that purpose because the middle..
segments are anyway left.Note
In the following place, I replaced
.
with the path to the directory containing the filebash_completion
, which is determined on the initialization. This aligns with the behavior described in the code comment.bash-completion/bash_completion
Lines 3175 to 3184 in 762f410
This means that we have been sourcing the file located in the completion in the actual current directory
./completions/xxx
, but this change will remove that behavior.