@@ -238,15 +238,6 @@ protected override bool ParseOption(string name, Bpl.CommandLineOptionEngine.Com
238238 case "plugin" : {
239239 if ( ps . ConfirmArgumentCount ( 1 ) ) {
240240 var pluginAndArgument = args [ ps . i ] ;
241- if ( pluginAndArgument . Length > 0 &&
242- pluginAndArgument [ 0 ] == '"' &&
243- pluginAndArgument [ ^ 1 ] == '"'
244- ) {
245- var unescapeRegex = new Regex ( @"\\""|\\\\" ) ;
246- pluginAndArgument = unescapeRegex . Replace ( pluginAndArgument . Substring ( 1 , pluginAndArgument . Length - 2 ) ,
247- match => match . Groups [ 0 ] . Value == @"\""" ? "\" " : @"\"
248- ) ;
249- }
250241 if ( pluginAndArgument . Length > 0 ) {
251242 var pluginArray = pluginAndArgument . Split ( ',' ) ;
252243 var pluginPath = pluginArray [ 0 ] ;
@@ -255,12 +246,7 @@ protected override bool ParseOption(string name, Bpl.CommandLineOptionEngine.Com
255246 // There are no commas in paths, but there can be in arguments
256247 var argumentsString = string . Join ( ',' , pluginArray . Skip ( 1 ) ) ;
257248 // Parse arguments, accepting and remove double quotes that isolate long arguments
258- var splitter = new Regex ( @"""((?:[^""]|\\"")*)""|([^ ]+)" ) ;
259- arguments = splitter . Matches ( argumentsString ) . Select (
260- matchResult => matchResult . Groups [ 1 ] . Success ?
261- matchResult . Groups [ 1 ] . Value . Replace ( @"\""" , @"""" ) :
262- matchResult . Groups [ 2 ] . Value
263- ) . ToArray ( ) ;
249+ arguments = ParsePluginArguments ( argumentsString ) ;
264250 }
265251 Plugins . Add ( Plugin . Load ( pluginPath , arguments ) ) ;
266252 }
@@ -546,6 +532,18 @@ protected override bool ParseOption(string name, Bpl.CommandLineOptionEngine.Com
546532 return TestGenOptions . ParseOption ( name , ps ) || base . ParseOption ( name , ps ) ;
547533 }
548534
535+ private static string [ ] ParsePluginArguments ( string argumentsString ) {
536+ var splitter = new Regex ( @"""(?<escapedArgument>(?:[^""\\]|\\\\|\\"")*)""|(?<rawArgument>[^ ]+)" ) ;
537+ var escapedChars = new Regex ( @"(?<escapedDoubleQuote>\\"")|\\\\" ) ;
538+ return splitter . Matches ( argumentsString ) . Select (
539+ matchResult =>
540+ matchResult . Groups [ "escapedArgument" ] . Success
541+ ? escapedChars . Replace ( matchResult . Groups [ "escapedArgument" ] . Value ,
542+ matchResult2 => matchResult2 . Groups [ "escapedDoubleQuote" ] . Success ? "\" " : "\\ " )
543+ : matchResult . Groups [ "rawArgument" ] . Value
544+ ) . ToArray ( ) ;
545+ }
546+
549547 protected void InvalidArgumentError ( string name , CommandLineParseState ps ) {
550548 ps . Error ( "Invalid argument \" {0}\" to option {1}" , ps . args [ ps . i ] , name ) ;
551549 }
0 commit comments