mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-11-15 01:28:17 -07:00
fix: warn if .tool-versions
or asdfrc contains carriage returns (#1561)
This commit is contained in:
parent
8e2aa5d726
commit
097f7733d6
@ -373,6 +373,8 @@ get_asdf_config_value_from_file() {
|
||||
return 1
|
||||
fi
|
||||
|
||||
util_validate_no_carriage_returns "$config_path"
|
||||
|
||||
local result
|
||||
result=$(grep -E "^\s*$key\s*=\s*" "$config_path" | head | sed -e 's/^[^=]*= *//' -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
|
||||
if [ -n "$result" ]; then
|
||||
@ -465,6 +467,8 @@ find_file_upwards() {
|
||||
search_path=$PWD
|
||||
while [ "$search_path" != "/" ]; do
|
||||
if [ -f "$search_path/$name" ]; then
|
||||
util_validate_no_carriage_returns "$search_path/$name"
|
||||
|
||||
printf "%s\n" "${search_path}/$name"
|
||||
return 0
|
||||
fi
|
||||
@ -863,6 +867,15 @@ util_resolve_user_path() {
|
||||
fi
|
||||
}
|
||||
|
||||
# @description Check if a file contains carriage returns. If it does, print a warning.
|
||||
util_validate_no_carriage_returns() {
|
||||
local file_path="$1"
|
||||
|
||||
if grep -qr $'\r' "$file_path"; then
|
||||
printf '%s\n' "asdf: Warning: File $file_path contains carriage returns. Please remove them." >&2
|
||||
fi
|
||||
}
|
||||
|
||||
get_plugin_remote_url() {
|
||||
local plugin_name="$1"
|
||||
local plugin_path
|
||||
|
@ -460,3 +460,16 @@ EOF
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "$message" ]
|
||||
}
|
||||
|
||||
@test "prints warning if .tool-versions file has carriage returns" {
|
||||
ASDF_CONFIG_FILE="$BATS_TEST_TMPDIR/asdfrc"
|
||||
cat >"$ASDF_CONFIG_FILE" <<<$'key2 = value2\r'
|
||||
|
||||
[[ "$(get_asdf_config_value "key1" 2>&1)" = *"contains carriage returns"* ]]
|
||||
}
|
||||
|
||||
@test "prints if asdfrc config file has carriage returns" {
|
||||
cat >".tool-versions" <<<$'nodejs 19.6.0\r'
|
||||
|
||||
[[ "$(find_tool_versions 2>&1)" = *"contains carriage returns"* ]]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user