diff --git a/nvm.sh b/nvm.sh index 1848c5b3..cce09848 100755 --- a/nvm.sh +++ b/nvm.sh @@ -1082,14 +1082,19 @@ nvm_process_nvmrc_content() { fi # Check for duplicate keys, in the shell: a symlinked `.nvmrc` can hold any file's content, - # and every local user can read a process's arguments - case "${keys} " in - *" ${key} "*) + # and every local user can read a process's arguments. + # Keys are newline-separated, since a key can contain a space but not a newline. + case "${keys} +" in + *" +${key} +"*) nvm_nvmrc_invalid_msg "${lines}" return 1 ;; esac - keys="${keys} ${key}" + keys="${keys} +${key}" values="${values} ${value}" else if [ -n "${unpaired_line}" ]; then diff --git a/test/fast/Unit tests/nvm_process_nvmrc_content rejects duplicate keys b/test/fast/Unit tests/nvm_process_nvmrc_content rejects duplicate keys index 6e681b3c..86cb8e10 100755 --- a/test/fast/Unit tests/nvm_process_nvmrc_content rejects duplicate keys +++ b/test/fast/Unit tests/nvm_process_nvmrc_content rejects duplicate keys @@ -25,7 +25,7 @@ ${KEY} = 3" done # keys are compared as they are written, not as patterns -for KEY in b ab A a. '*' '.*' '?' 'a|b' '[a]'; do +for KEY in b ab A a. '*' '.*' '?' 'a|b' '[a]' 'a b' 'b a' 'b a'; do for CONTENT in "20 a=1 ${KEY}=2" "20