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

Validate that all arguments provided for an hs.task, are strings #3664

Merged
merged 1 commit into from
Aug 9, 2024
Merged
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
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
Loading