Skip to content

Commit

Permalink
Validate that all arguments provided for an hs.task, are strings. Closes
Browse files Browse the repository at this point in the history
  • Loading branch information
cmsj committed Aug 9, 2024
1 parent d6f8f9c commit ec9a8ea
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions extensions/task/libtask.m
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ void create_task(task_userdata_t *userData) {
/// * arguments - An optional table of command line argument strings for the executable
///
/// Returns:
/// * An `hs.task` object
/// * An `hs.task` object or nil if an error occurred
///
/// Notes:
/// * The arguments are not processed via a shell, so you do not need to do any quoting or escaping. They are passed to the executable exactly as provided.
Expand Down Expand Up @@ -231,14 +231,28 @@ static int task_new(lua_State *L) {
userData->launchPath = (__bridge_retained void *)[skin toNSObjectAtIndex:1];
userData->inputData = nil;

NSArray *arguments = nil;

if (lua_type(L, 3) == LUA_TTABLE) {
userData->arguments = (__bridge_retained void *)[skin toNSObjectAtIndex:3];
arguments = [skin toNSObjectAtIndex:3];
} else if (lua_type(L, 4) == LUA_TTABLE) {
userData->arguments = (__bridge_retained void *)[skin toNSObjectAtIndex:4];
arguments = [skin toNSObjectAtIndex:4];
} else {
userData->arguments = (__bridge_retained void *)[[NSArray alloc] init];
arguments = [[NSArray alloc] init];
}

// Ensure all of our arguments are strings
for (id element in arguments) {
if (![element isKindOfClass:[NSString class]]) {
[skin logError:@"All arguments for hs.task.new must be strings"];
lua_pushnil(L);
return 1;
}
}

// Store the arguments
userData->arguments = (__bridge_retained void *)arguments;

// Create and populate the NSTask object
create_task(userData);

Expand Down

0 comments on commit ec9a8ea

Please sign in to comment.