Repository navigation
[Fix] Remove $NVM_DIR trailing slash automatically, fix #1708 - #1734
Conversation
| NVM_DIR="$(nvm_cd ${NVM_CD_FLAGS} "$(dirname "${NVM_SCRIPT_SOURCE:-$0}")" > /dev/null && \pwd)" | ||
| export NVM_DIR | ||
| else | ||
| while echo "${NVM_DIR}" | nvm_grep -q "/$"; do |
There was a problem hiding this comment.
This is way overly complex; export NVM_DIR="${NVM_DIR%/}" should be sufficient.
It'd be nice if we also output a warning when this happens so people know they've set an invalid directory path.
Also, can we add some tests for this?
There was a problem hiding this comment.
Test if we could remove the trailing slash with success? I think the trailing slashes would be valid in many places as I replied on the issue, and the complexity overhead is not that high here, remove them as many as possible as we can could be much more flexible here, what do you think?
There was a problem hiding this comment.
If someone has multiple trailing slashes in their profile file, or even any, then it's incorrect. I don't just want to silently fix their error, I also want to let them know that they have one.
There was a problem hiding this comment.
Okay, fixed now.
bace013 to
732d380
Compare
|
Should be good now :) |
|
This still doesn't output a warning though when there's a trailing slash. |
732d380 to
ca5c934
Compare
|
Should be good now :) |
| # shellcheck disable=SC1001 | ||
| NVM_DIR="$(nvm_cd ${NVM_CD_FLAGS} "$(dirname "${NVM_SCRIPT_SOURCE:-$0}")" > /dev/null && \pwd)" | ||
| export NVM_DIR | ||
| elif echo "${NVM_DIR}" | nvm_grep -q "/$"; then |
There was a problem hiding this comment.
| export NVM_DIR | ||
| elif echo "${NVM_DIR}" | nvm_grep -q "/$"; then | ||
| export NVM_DIR="${NVM_DIR%/}" | ||
| nvm_err "Warning: \$NVM_DIR should not have trailing space" |
There was a problem hiding this comment.
Oh ... my fault
ca5c934 to
77e2c95
Compare
|
I suppose I'll need to separate it to a function so that I can write its unit test, any idea like what's the name of its function you'd like? |
|
@PeterDaveHello hm, not sure - "remove_trailing_slash" perhaps. but, does this need a separate function, or can it be tested by setting NVM_DIR in a test prior to sourcing nvm.sh? |
|
The second way will be simpler ;) |
77e2c95 to
b1e3c6a
Compare
|
Updated. |
|
|
||
| \. ../../nvm.sh | ||
|
|
||
| [ "${NVM_DIR}" = "${NVM_DIR_BASE}" ] && die 'nvm should only remove the last trailing slash in "$NVM_DIR"' |
There was a problem hiding this comment.
this "die" message seems incorrect; it should remove all trailing slashes in NVM_DIR, no?
There was a problem hiding this comment.
Nope, that was my original idea but rejected here: #1734 (comment), I can revise it back if you want.
There was a problem hiding this comment.
ah - so what I intended in that comment was for nvm to fail outright when there was any trailing slashes in NVM_DIR.
The alternative is to remove all of them, and output a warning so they can fix it.
There was a problem hiding this comment.
yeah I've tested the case that there is only single slash and was removed, so to make sure we'll only remove the last slash, maybe I don't need to revise the tests here?
There was a problem hiding this comment.
To clarify further: if we go with removal, I think it should remove all trailing slashes, not just one.
There was a problem hiding this comment.
Rollbacked now ...
b1e3c6a to
30bc836
Compare
5c5eadc to
09f7bbb
Compare
This can automatically remove the trailing slash in
$NVM_DIRwhen loadingnvm, the trailing space isn't that invalid.Fixes #1708.