From a91a709a8d70dc417a54eea5e5b271e04d8fa828 Mon Sep 17 00:00:00 2001 From: chirsz Date: Mon, 12 Oct 2020 03:57:08 +0800 Subject: [PATCH] [CMD] Fix a typo in filename completion (#3293) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix filename completion that could cause a incorrect result when the path contains "dots". (See also HBelusca@d12169b.) See CORE-8623 and CORE-1901 (bug introduced in r25896 / 54cf74f). For example: - The current directory is `C:\Documents and Settings\Administrator\`, and you input `".` and press TAB. The completion result would be `".Administrator"`, which even does not exist. - You input "some(file).ext", and you remove the final quote (or the quote and "ext") and you attempt to complete the file name. - Import two additional fixes from HBelusca@a826730: Fix the search ordering in the comparisons between szSearch1, szSearch2 and szSearch3. Co-authored-by: Hermès BÉLUSCA - MAÏTO --- base/shell/cmd/filecomp.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/base/shell/cmd/filecomp.c b/base/shell/cmd/filecomp.c index 9dfa2943fdc..4e486692a66 100644 --- a/base/shell/cmd/filecomp.c +++ b/base/shell/cmd/filecomp.c @@ -394,10 +394,10 @@ VOID FindPrefixAndSuffix(LPTSTR strIN, LPTSTR szPrefix, LPTSTR szSuffix) /* Find the one closest to end */ szSearch1 = _tcsrchr(str, _T('\"')); szSearch2 = _tcsrchr(str, _T('\\')); - szSearch3 = _tcsrchr(str, _T('.')); - if (szSearch2 != NULL && _tcslen(szSearch1) > _tcslen(szSearch2)) + szSearch3 = _tcsrchr(str, _T('/')); + if ((szSearch2 != NULL) && (szSearch1 < szSearch2)) szSearch = szSearch2; - else if (szSearch3 != NULL && _tcslen(szSearch1) > _tcslen(szSearch3)) + else if ((szSearch3 != NULL) && (szSearch1 < szSearch3)) szSearch = szSearch3; else szSearch = szSearch1; @@ -440,9 +440,9 @@ VOID FindPrefixAndSuffix(LPTSTR strIN, LPTSTR szPrefix, LPTSTR szSuffix) szSearch1 = _tcsrchr(str, _T(' ')); szSearch2 = _tcsrchr(str, _T('\\')); szSearch3 = _tcsrchr(str, _T('/')); - if (szSearch2 != NULL && _tcslen(szSearch1) > _tcslen(szSearch2)) + if ((szSearch2 != NULL) && (szSearch1 < szSearch2)) szSearch = szSearch2; - else if (szSearch3 != NULL && _tcslen(szSearch1) > _tcslen(szSearch3)) + else if ((szSearch3 != NULL) && (szSearch1 < szSearch3)) szSearch = szSearch3; else szSearch = szSearch1;