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

feat: check command input is valid array #290

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

SimplyFaisal
Copy link

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.

@SimplyFaisal
Copy link
Author

@iamhopaul123 can you review this please? Thanks!

@amazreech
Copy link
Contributor

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:

  1. Verify if PR follows semantic pull request conventions.

  2. Please run npm run package command to update dist/ folder with latest dependencies.

  3. Resolve merge conflicts on the PR

@SimplyFaisal
Copy link
Author

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);
Copy link
Contributor

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.');
Copy link
Contributor

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?

@amazreech
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants