@@ -1220,7 +1220,6 @@ pub const ArgIteratorPosix = struct {
12201220pub const ArgIteratorWindows = struct {
12211221 index : usize ,
12221222 cmd_line : & const u8 ,
1223- backslash_count : usize ,
12241223 in_quote : bool ,
12251224 quote_count : usize ,
12261225 seen_quote_count : usize ,
@@ -1233,7 +1232,6 @@ pub const ArgIteratorWindows = struct {
12331232 return ArgIteratorWindows {
12341233 .index = 0 ,
12351234 .cmd_line = cmd_line ,
1236- .backslash_count = 0 ,
12371235 .in_quote = false ,
12381236 .quote_count = countQuotes (cmd_line ),
12391237 .seen_quote_count = 0 ,
@@ -1266,25 +1264,30 @@ pub const ArgIteratorWindows = struct {
12661264 }
12671265 }
12681266
1267+ var backslash_count : usize = 0 ;
12691268 while (true ) : (self .index += 1 ) {
12701269 const byte = self .cmd_line [self .index ];
12711270 switch (byte ) {
12721271 0 = > return true ,
12731272 '"' = > {
1274- const quote_is_real = self . backslash_count % 2 == 0 ;
1273+ const quote_is_real = backslash_count % 2 == 0 ;
12751274 if (quote_is_real ) {
12761275 self .seen_quote_count += 1 ;
12771276 }
12781277 },
12791278 '\\ ' = > {
1280- self . backslash_count += 1 ;
1279+ backslash_count += 1 ;
12811280 },
12821281 ' ' , '\t ' = > {
12831282 if (self .seen_quote_count % 2 == 0 or self .seen_quote_count == self .quote_count ) {
12841283 return true ;
12851284 }
1285+ backslash_count = 0 ;
1286+ },
1287+ else = > {
1288+ backslash_count = 0 ;
1289+ continue ;
12861290 },
1287- else = > continue ,
12881291 }
12891292 }
12901293 }
@@ -1293,13 +1296,15 @@ pub const ArgIteratorWindows = struct {
12931296 var buf = % return Buffer .initSize (allocator , 0 );
12941297 defer buf .deinit ();
12951298
1299+ var backslash_count : usize = 0 ;
12961300 while (true ) : (self .index += 1 ) {
12971301 const byte = self .cmd_line [self .index ];
12981302 switch (byte ) {
12991303 0 = > return buf .toOwnedSlice (),
13001304 '"' = > {
1301- const quote_is_real = self .backslash_count % 2 == 0 ;
1302- % return self .emitBackslashes (& buf , self .backslash_count / 2 );
1305+ const quote_is_real = backslash_count % 2 == 0 ;
1306+ % return self .emitBackslashes (& buf , backslash_count / 2 );
1307+ backslash_count = 0 ;
13031308
13041309 if (quote_is_real ) {
13051310 self .seen_quote_count += 1 ;
@@ -1311,26 +1316,27 @@ pub const ArgIteratorWindows = struct {
13111316 }
13121317 },
13131318 '\\ ' = > {
1314- self . backslash_count += 1 ;
1319+ backslash_count += 1 ;
13151320 },
13161321 ' ' , '\t ' = > {
1317- % return self .emitBackslashes (& buf , self .backslash_count );
1322+ % return self .emitBackslashes (& buf , backslash_count );
1323+ backslash_count = 0 ;
13181324 if (self .seen_quote_count % 2 == 1 and self .seen_quote_count != self .quote_count ) {
13191325 % return buf .appendByte (byte );
13201326 } else {
13211327 return buf .toOwnedSlice ();
13221328 }
13231329 },
13241330 else = > {
1325- % return self .emitBackslashes (& buf , self .backslash_count );
1331+ % return self .emitBackslashes (& buf , backslash_count );
1332+ backslash_count = 0 ;
13261333 % return buf .appendByte (byte );
13271334 },
13281335 }
13291336 }
13301337 }
13311338
13321339 fn emitBackslashes (self : & ArgIteratorWindows , buf : & Buffer , emit_count : usize ) - > % void {
1333- self .backslash_count = 0 ;
13341340 var i : usize = 0 ;
13351341 while (i < emit_count ) : (i += 1 ) {
13361342 % return buf .appendByte ('\\ ' );
@@ -1400,6 +1406,9 @@ test "windows arg parsing" {
14001406 testWindowsCmdLine (c"a\\\\\\ \" b c d" , [][]const u8 {"a\\ \" b" , "c" , "d" });
14011407 testWindowsCmdLine (c"a\\\\\\\\ \" b c\" d e" , [][]const u8 {"a\\\\ b c" , "d" , "e" });
14021408 testWindowsCmdLine (c"a b\t c \" d f" , [][]const u8 {"a" , "b" , "c" , "\" d" , "f" });
1409+
1410+ testWindowsCmdLine (c"\" .\\ ..\\ zig-cache\\ build\" \" bin\\ zig.exe\" \" .\\ ..\" \" .\\ ..\\ zig-cache\" \" --help\" " ,
1411+ [][]const u8 {".\\ ..\\ zig-cache\\ build" , "bin\\ zig.exe" , ".\\ .." , ".\\ ..\\ zig-cache" , "--help" });
14031412}
14041413
14051414fn testWindowsCmdLine (input_cmd_line : & const u8 , expected_args : []const []const u8 ) {
0 commit comments