Skip to content

Commit

Permalink
fix: make sure that files with + in their name get escaped
Browse files Browse the repository at this point in the history
otherwise if you have a command like g++, csv++ you will see the
following error:

 grep: repetition-operator operand invalid

MINOR: fixes a bug for keys with `+` characters
  • Loading branch information
patrickomatic committed May 3, 2023
1 parent 684f4f0 commit 685734f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ get_preset_version_for() {

get_asdf_config_value_from_file() {
local config_path=$1
local key=$2
local key=$(escape_regexp $2)

if [ ! -f "$config_path" ]; then
return 1
Expand Down Expand Up @@ -628,6 +628,12 @@ is_executable() {
return 1
}

escape_regexp() {
# if the plugin in question has special characters (+, ., * or ?) it will cause any grep or sed
# calls with that plugin name to fail
printf "%s" $1 | sed -e "s/\([.+*?]\)/\\\\\1/g"
}

plugin_shims() {
local plugin_name=$1
local full_version=$2
Expand Down
19 changes: 19 additions & 0 deletions test/utils.bats
Original file line number Diff line number Diff line change
Expand Up @@ -460,3 +460,22 @@ EOF
[ "$status" -eq 0 ]
[ "$output" = "$message" ]
}

@test "with_shim_executable doesn't crash when executable names contain plusses" {
cd "$PROJECT_DIR"
echo "dummy 0.1.0" >"$PROJECT_DIR/.tool-versions"
mkdir -p "$ASDF_DIR/installs/dummy/0.1.0/bin"
touch "$ASDF_DIR/installs/dummy/0.1.0/bin/test++"
chmod +x "$ASDF_DIR/installs/dummy/0.1.0/bin/test++"
run asdf reshim dummy 0.1.0

message="callback invoked"

callback() {
echo "$message"
}

run with_shim_executable test++ callback
[ "$status" -eq 0 ]
[ "$output" = "$message" ]
}

0 comments on commit 685734f

Please sign in to comment.