Kaynağa Gözat

SysTools.quoteWinArg: add quotes if argument contains slashes (closes #10468)

Aleksandr Kuzmenko 3 yıl önce
ebeveyn
işleme
b159a634eb
2 değiştirilmiş dosya ile 12 ekleme ve 2 silme
  1. 2 2
      std/haxe/SysTools.hx
  2. 10 0
      tests/unit/src/unit/issues/Issue10468.hx

+ 2 - 2
std/haxe/SysTools.hx

@@ -45,12 +45,12 @@ class SysTools {
 	**/
 	public static function quoteWinArg(argument:String, escapeMetaCharacters:Bool):String {
 		// If there is no space, tab, back-slash, or double-quotes, and it is not an empty string.
-		if (!~/^[^ \t\\"]+$/.match(argument)) {
+		if (!~/^(\/)?[^ \t\/\\"]+$/.match(argument)) {
 			// Based on cpython's subprocess.list2cmdline().
 			// https://hg.python.org/cpython/file/50741316dd3a/Lib/subprocess.py#l620
 
 			var result = new StringBuf();
-			var needquote = argument.indexOf(" ") != -1 || argument.indexOf("\t") != -1 || argument == "";
+			var needquote = argument.indexOf(" ") != -1 || argument.indexOf("\t") != -1 || argument == "" || argument.indexOf("/") > 0;
 
 			if (needquote)
 				result.add('"');

+ 10 - 0
tests/unit/src/unit/issues/Issue10468.hx

@@ -0,0 +1,10 @@
+package unit.issues;
+
+import haxe.SysTools;
+
+class Issue10468 extends Test {
+	function test() {
+		eq('"some/path"', SysTools.quoteWinArg('some/path', false));
+		eq('/S', SysTools.quoteWinArg('/S', false));
+	}
+}