Skip to content

Commit

Permalink
system: fix argument parsing of spaces in middle
Browse files Browse the repository at this point in the history
Fixes #3579
  • Loading branch information
osy committed Feb 13, 2022
1 parent 804b3b0 commit 0bc74f8
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions Managers/UTMQemuSystem.m
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ - (void)argsFromUser {
if (self.configuration.systemArguments.count != 0) {
NSArray *addArgs = self.configuration.systemArguments;
// Splits all spaces into their own, except when between quotes.
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"(\"[^\"]+\"|\\+|\\S+)" options:0 error:nil];
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"((?:[^\"\\s]*\"[^\"]*\"[^\"\\s]*)+|[^\"\\s]+)" options:0 error:nil];

for (NSString *arg in addArgs) {
// No need to operate on empty arguments.
Expand All @@ -717,9 +717,7 @@ - (void)argsFromUser {
for (NSTextCheckingResult *match in splitArgsArray) {
NSRange matchRange = [match rangeAtIndex:1];
NSString *argFragment = [arg substringWithRange:matchRange];
if ([argFragment hasPrefix:@"\""] && [argFragment hasSuffix:@"\""]) {
argFragment = [argFragment substringWithRange:NSMakeRange(1, argFragment.length-2)];
}
argFragment = [argFragment stringByReplacingOccurrencesOfString:@"\"" withString:@""];
[self pushArgv:argFragment];
}
}
Expand Down

0 comments on commit 0bc74f8

Please sign in to comment.