Skip to content

Commit

Permalink
Do not search in PATH when opening relative paths via command line
Browse files Browse the repository at this point in the history
When following command is executed `notepad2.exe config` instead of asking for
"File not found would you like to create" dialog, it tries to open
C:\Windows\system32\config with open file dialog. This is happening because
notepad2 tries to search in PATH variable when a relative path is provided

Fix: Do not search in PATH variable when a relative path is given at the command line

Signed-off-by: Vineel Kumar Reddy Kovvuri <vineel.kovvuri@gmail.com>
  • Loading branch information
vineelkovvuri committed Jan 14, 2019
1 parent 56b767d commit bb50494
Showing 1 changed file with 1 addition and 17 deletions.
18 changes: 1 addition & 17 deletions src/Notepad2.c
Original file line number Diff line number Diff line change
Expand Up @@ -6876,12 +6876,6 @@ BOOL FileLoad(BOOL bDontSave, BOOL bNew, BOOL bReload, BOOL bNoEncDetect, LPCWST
if (PathIsRelative(tch)) {
lstrcpyn(szFileName, g_wchWorkingDirectory, COUNTOF(szFileName));
PathAppend(szFileName, tch);
if (!PathFileExists(szFileName)) {
WCHAR wchFullPath[MAX_PATH];
if (SearchPath(NULL, tch, NULL, COUNTOF(wchFullPath), wchFullPath, NULL)) {
lstrcpy(szFileName, wchFullPath);
}
}
} else {
lstrcpy(szFileName, tch);
}
Expand Down Expand Up @@ -7326,17 +7320,7 @@ BOOL ActivatePrevInst(void) {
if (PathIsRelative(lpFileArg)) {
lstrcpyn(tchTmp, g_wchWorkingDirectory, COUNTOF(tchTmp));
PathAppend(tchTmp, lpFileArg);
if (PathFileExists(tchTmp)) {
lstrcpy(lpFileArg, tchTmp);
} else {
if (SearchPath(NULL, lpFileArg, NULL, COUNTOF(tchTmp), tchTmp, NULL)) {
lstrcpy(lpFileArg, tchTmp);
} else {
lstrcpyn(tchTmp, g_wchWorkingDirectory, COUNTOF(tchTmp));
PathAppend(tchTmp, lpFileArg);
lstrcpy(lpFileArg, tchTmp);
}
}
lstrcpy(lpFileArg, tchTmp);
} else if (SearchPath(NULL, lpFileArg, NULL, COUNTOF(tchTmp), tchTmp, NULL)) {
lstrcpy(lpFileArg, tchTmp);
}
Expand Down

0 comments on commit bb50494

Please sign in to comment.