Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle shell operations with spaces and quotes #426

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Slate/ShellOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ + (id)shellOperationFromString:(NSString *)shellOperation {
}
NSString *commandAndArgs = [tokens lastObject];
NSMutableArray *commandAndArgsTokens = [NSMutableArray array];
[StringTokenizer tokenize:commandAndArgs into:commandAndArgsTokens];
[StringTokenizer tokenize:commandAndArgs into:commandAndArgsTokens quoteChars:[NSCharacterSet characterSetWithCharactersInString:QUOTES]];
if ([commandAndArgsTokens count] < 1) {
SlateLogger(@"ERROR: Invalid Parameters '%@'", shellOperation);
@throw([NSException exceptionWithName:@"Invalid Parameters" reason:[NSString stringWithFormat:@"Invalid Parameters in '%@'. Shell operations require the following format: shell [wait] 'command'", shellOperation] userInfo:nil]);
Expand Down
8 changes: 8 additions & 0 deletions SlateTests/TestShellUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#import "TestShellUtils.h"
#import "ShellUtils.h"
#import "ShellOperation.h"

@implementation TestShellUtils

Expand Down Expand Up @@ -53,4 +54,11 @@ - (void)testRunWithQuotedArgs {
STAssertEquals(found, 1, @"Result should include all strings");
}

-(void)testShellOperationFromStringWithQuotesAndSpaces {
id operation = [ShellOperation shellOperationFromString:@"shell '/usr/bin/open -a \"Sublime Text\"'"];
int argumentCount = [[operation args] count];

STAssertEquals(argumentCount, 2, @"The shell operation must only contain two arguments");
}

@end