-
Notifications
You must be signed in to change notification settings - Fork 144
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
feat: check command input is valid array #290
base: master
Are you sure you want to change the base?
Conversation
@iamhopaul123 can you review this please? Thanks! |
Hi @SimplyFaisal, thank you so much for your contribution. Apologies on the delay. We will be working on reviewing Pull Requests on the repositories. In the mean time please ensure that below steps, if not already done, are taken care of in your PR:
|
Thanks for the info @amazreech. Confirming that the above requests are satisfied. |
const parsedCommand = JSON.parse(command); | ||
if (!Array.isArray(parsedCommand)) { | ||
// The parsed object is not an array. | ||
throw new Error(invalidCommandErrorMessage); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, please correct me if my understanding here is not correct:
Taking the example input you mentioned in PR description: alembic revision --autogenerate -m "Your message here"
The input will be marked as invalid command in this case, but before your change it would be considered correct but would eventually fail, Is this correct?
|
||
await run(); | ||
|
||
expect(core.setFailed).toBeCalledWith('Invalid command: \'npm start --nice --please\'. command must be a valid JSON array.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please feel free to add additional insights to this, but seems like this change would render previously "valid" commands as "invalid" for other users.
For example npm start --nice --please
would be expected to pass earlier but with this change, users would be required to change the format in which they provide the command
field.
Is this correct?
Hi @SimplyFaisal, I have added few comments to clarify my understand of the solution provided here. Please do respond with your thoughts. Also, the unit tests seem to be failing for this, would you also be able to take a look at that. |
Issue #, if available:
Description of changes:
Commands that include spaces within arguments, special characters, or need quoting can break if naively split on whitespace(
command.split(' ')
) .Take for example this input:
alembic revision --autogenerate -m "Your message here"
.Splitting on whitespace will result in container def receving the command
[ "alembic", "revision", "--autogenerate", " -m", "Your", "message", " here"]
which is incorrect and will result in an error when the command is run.This PR solves this by validating that the command input is a valid array and adding it to the container definition. Otherwise an error is thrown.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.