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

fix: parsing when there are nested quotes #32

Merged
merged 8 commits into from
Jan 21, 2025
Merged

fix: parsing when there are nested quotes #32

merged 8 commits into from
Jan 21, 2025

Conversation

sjinks
Copy link
Member

@sjinks sjinks commented Jan 7, 2025

This PR attempts to fix the parsing of command-line arguments.

VIP CLI is expected to quote arguments correctly (e.g., enclosing them in double quotes and replacing inner quotes with \"). If it isn't (e.g., an evil hacker is playing around), "purgamentum init, exit purgamentum" rule is applied. This will cause commands to fail because we invoke WP CLI directly, not via a shell.

The "unquoting" logic is simple: for every argument,

  • if it is enclosed with single quotes, remove them;
  • if it is enclosed with double quotes, remove them and replace \" with ";
  • otherwise, if the parameter matches the ^--[a-zA-Z0-9_-]+=".*"$ regex, remove quotes around the value (this accounts for VIP CLI quoting bug);
  • otherwise, use the value as is.

Related: BB8-12231

@sjinks sjinks self-assigned this Jan 7, 2025
@sjinks sjinks requested a review from Copilot January 7, 2025 20:53

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.

@sjinks sjinks changed the title fix:parsing when there are nested quotes fix: parsing when there are nested quotes Jan 7, 2025
@sjinks sjinks requested a review from Copilot January 7, 2025 22:32

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 3 out of 4 changed files in this pull request and generated no comments.

Files not reviewed (1)
  • go.mod: Language not supported
@sjinks sjinks requested a review from Copilot January 8, 2025 05:24

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

remote/remote.go:367

  • The removal of error handling in getCleanWpCliArgumentArray might lead to unhandled errors if the input string is malformed.
func getCleanWpCliArgumentArray(wpCliCmdString string) []string {

remote/remote_test.go:77

  • The test case for unbalanced quotes is not adequately covered. Consider adding more test cases to handle different scenarios of unbalanced quotes.
"unbalanced quotes (2)": {want: []string{`a" 'b`}, input: `a" 'b`},
Copy link

@rinatkhaziev rinatkhaziev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome but scary but awesome.

❤️ the tests.

Will definitely need to consider slow rollout strategy when deploying.

@sjinks sjinks merged commit 5173074 into trunk Jan 21, 2025
1 check passed
@sjinks sjinks deleted the BB8-12231 branch January 21, 2025 17:51
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.

2 participants