util+buffer: Accept both path separators on Windows - #4178
Open
4RH1T3CT0R7 wants to merge 1 commit into
Open
Conversation
Windows accepts `/` as well as `\`, but `ReplaceHome()` only looked for `/` when determining where the `~` component ends, while `FileComplete()` only split on `os.PathSeparator` and always appended `os.PathSeparator` to directory suggestions. As a result `~\foo.txt` was rejected with "Could not find user", neither `~/foo`, `~\foo` nor `C:/Users/User/foo` could be completed, and completing a directory mixed the separators. Normalize the path with `filepath.ToSlash()` before splitting and keep completing with the separator already in use. Both are a no-op on Unix, where `\` is a regular filename character. Fixes micro-editor#3828
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.
On Windows both
/and\work as separators, but a couple of spots assume one.ReplaceHome()splits on/to find the end of the~component, so~\foo.txtturns into a user lookup for the whole string and fails with "Could not find user".FileComplete()splits onos.PathSeparatoronly, so a forward-slash path likeC:/Users/User/fo<Tab>gives no suggestions at all.Both now normalize with
filepath.ToSlash(), and completion hands back whichever separator the input already uses, soC:/Users/User/sucompletes tosubdir/rather thansubdir\. No-ops on Unix, where\is an ordinary filename character. Tests cover both separators.#3955 rewrites the same
ReplaceHome()line but hardcodes/more firmly, so~\foo.txtstill breaks there.Fixes #3828