Skip to content

Commit d9b70e4

Browse files
authored
Merge pull request #8 from ahmetoozcan/powershell-path-corrupt-fix
Closes #7
2 parents 967f99f + 7fe67f0 commit d9b70e4

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

Main.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private static bool _IsValidPath(string path)
5555
{
5656
int c = path[i];
5757

58-
if (c == '<' || c == '>' || c == '|' || c == '*' || c == '?' || c < 32)
58+
if (c == '<' || c == '>' || c == '|' || c == '*' || c == '?' || c < 32 || c == '/')
5959
return false;
6060
}
6161

@@ -210,6 +210,9 @@ public List<Result> Query(Query query)
210210
Context.API.ShowMsgError("Failed to add to PATH", $"Failed to add {$"\"{folderPath}\""} to {(system ? "system" : "user")} PATH - {ex.Message}");
211211
return true;
212212
}
213+
if (folderPath.Contains(';')) {
214+
Context.API.ShowMsgError("Warning to Powershell users", "This path won't work in Powershell because it contains a semicolon. For more information, visit https://github.com/HorridModz/Flow.Launcher.Plugin.Add2Path/pull/8");
215+
}
213216
Context.API.ShowMsg("Successfully added to PATH", $"Successfully added {$"\"{folderPath}\""} to {(system ? "system" : "user")} PATH.");
214217
return true;
215218
},

PathUtils.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ public static string _EncodeParameterArgument(string original)
9393
if (string.IsNullOrEmpty(original))
9494
return original;
9595
string value = Regex.Replace(original, @"(\\*)" + "\"", @"$1\$0");
96-
value = Regex.Replace(value, @"^(.*\s.*?)(\\*)$", "\"$1$2$2\"");
97-
return value;
96+
return Regex.Replace(value, @"^(.*\s.*?)(\\*)$", "\"$1$2$2\"");
9897
}
9998

10099
private static string _GetRegistryKey(bool system = false)
@@ -148,8 +147,13 @@ public static void SetFullString(string value, bool system = false)
148147

149148
public static void Set(List<string> folderPaths, bool system = false)
150149
{
151-
// Wrap folder paths in quotes
152-
folderPaths = (from folderPath in folderPaths select $"\"{folderPath}\"").ToList();
150+
// ?: Windows wraps paths with semicolon (;) as default,
151+
// ?: this way CMD can read path value by discarding path seperator character
152+
// ?: (which is semicolon for in this case) which is between double quotes
153+
// !: But in the other hand path with semicolons won't be working on Powershell because Powershell
154+
// !: doesn't trims any double quotes and seperates paths only by checking path seperator character
155+
// ?: You can check all the details from https://github.com/HorridModz/Flow.Launcher.Plugin.Add2Path/pull/8
156+
folderPaths = (from folderPath in folderPaths select folderPath.Contains(';') ? $"\"{folderPath}\"" : folderPath).ToList();
153157
PathUtils.SetFullString(String.Join(";", folderPaths), system);
154158
}
155159

0 commit comments

Comments
 (0)