Fix has_local to not search PATH for external 'local' command - #5018
Open
harriiinnii wants to merge 1 commit into
Open
Fix has_local to not search PATH for external 'local' command#5018harriiinnii wants to merge 1 commit into
harriiinnii wants to merge 1 commit into
Conversation
On systems where /bin/sh has no builtin `local`, `has_local` would fall through and search $PATH for a command named `local`. If such a command existed there, it would be incorrectly used as the alias target. Fix by setting PATH= before the `local` call so that $PATH is not consulted for the fallback, matching the behavior on shells that have a builtin `local`. Fixes rust-lang#5009
Member
|
@harriiinnii Oops, it seems like your change is not a pure refactoring step? Would you mind doing some more digging? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
has_local()inrustup-init.shis used to detect whether the shell has a builtinlocalkeyword. On shells that lack it, the function falls through and the script aliaseslocaltotypeset.However, if the shell has no builtin
localand an executable namedlocalhappens to exist somewhere in$PATH, that external command would be found and used instead — makinghas_localreturn success incorrectly. Any subsequentlocalusage would then invoke that external command rather than thetypesetalias.Fix
Set
PATH=before thelocalcall insidehas_local. This prevents the shell from searching$PATHfor alocalexecutable: on shells with a builtinlocalthe call succeeds as before, and on shells without it the call correctly fails even if an externallocalexists in$PATH.Fixes #5009