From 76e84c5c22d5beb15227e74bd7ed55d24e399c2e Mon Sep 17 00:00:00 2001 From: Ven0m0 <82972344+Ven0m0@users.noreply.github.com> Date: Wed, 29 Apr 2026 00:34:17 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20Add=20edge=20case=20tests=20and?= =?UTF-8?q?=20fixes=20for=20FindExe?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> --- Lib/v2/AHK_Common.ahk | 6 ++++-- tests/FindExe_Test.ahk | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Lib/v2/AHK_Common.ahk b/Lib/v2/AHK_Common.ahk index 78055fa..494f3a1 100644 --- a/Lib/v2/AHK_Common.ahk +++ b/Lib/v2/AHK_Common.ahk @@ -48,14 +48,16 @@ InitScript(requireUIA := true, requireAdmin := false, optimize := true) { } FindExe(name, fallbacks := []) { + if (name == "") + return "" if FileExist(name) return name Loop Parse, EnvGet("PATH"), ";" { - p := Trim(A_LoopField) + p := Trim(A_LoopField, " `t`"") if !p continue - cand := p . "\" . name + cand := RTrim(p, "\") . "\" . name if FileExist(cand) return cand } diff --git a/tests/FindExe_Test.ahk b/tests/FindExe_Test.ahk index 0d02a0d..3e7e413 100644 --- a/tests/FindExe_Test.ahk +++ b/tests/FindExe_Test.ahk @@ -59,6 +59,21 @@ try { EnvSet("PATH", ";;" . mockPath . ";;") AssertEqual(testBaseDir . "\PathDir2\tool.exe", FindExe("tool.exe"), "Should handle empty entries in PATH") + ; Test 6: Whitespace around PATH entries + EnvSet("PATH", " " . testBaseDir . "\PathDir2 ") + AssertEqual(testBaseDir . "\PathDir2\tool.exe", FindExe("tool.exe"), "Should handle whitespace in PATH entries") + + ; Test 7: Quotes in PATH entries + EnvSet("PATH", "`"" . testBaseDir . "\PathDir2`"") + AssertEqual(testBaseDir . "\PathDir2\tool.exe", FindExe("tool.exe"), "Should handle quotes in PATH entries") + + ; Test 8: Trailing slashes in PATH entries + EnvSet("PATH", testBaseDir . "\PathDir2\") + AssertEqual(testBaseDir . "\PathDir2\tool.exe", FindExe("tool.exe"), "Should handle trailing slashes in PATH entries") + + ; Test 9: Empty name parameter + AssertEqual("", FindExe(""), "Should return empty string if name is empty") + ; Final Results stdout.WriteLine("---") stdout.WriteLine("Tests Passed: " . testsPassed)