[CMD] Fix a typo in filename completion (#3293)

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 <hermes.belusca-maito@reactos.org>
This commit is contained in:
chirsz 2020-10-12 03:57:08 +08:00 committed by GitHub
parent 7a2c1f7d0b
commit a91a709a8d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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;