Skip to content

Fix #28 -- escaping arguments as mentioned in TODO #2093

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

Merged
merged 1 commit into from
Mar 8, 2019

Conversation

jonasfj
Copy link
Member

@jonasfj jonasfj commented Mar 5, 2019

I just want to close: #28

@jonasfj jonasfj requested a review from sigurdm March 5, 2019 15:19
// Escape the argument for users to copy-paste in bash.
protectArgument(String x) =>
RegExp(r'^[a-zA-Z0-9-_]+$').stringMatch(x) == null
? "'${x.replaceAll("'", "'\\''")}'"
Copy link
Contributor

Choose a reason for hiding this comment

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

You cannot escape a single quote inside a single quote:
https://www.gnu.org/software/bash/manual/html_node/Single-Quotes.html#Single-Quotes
You probably need to use double quotes and escape all of ‘$’, ‘`’, ‘\’

Copy link
Member Author

Choose a reason for hiding this comment

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

Not really... Read carefully I escape single quote, by ending single quotation then having an escaped single quote and starting single quotation again :)

If there is no space between end and start of single quotation it doesn't become a new argument...

Copy link
Contributor

Choose a reason for hiding this comment

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

Explain this in a comment ...

// Escape the argument for users to copy-paste in bash.
protectArgument(String x) =>
RegExp(r'^[a-zA-Z0-9-_]+$').stringMatch(x) == null
? "'${x.replaceAll("'", "'\\''")}'"
Copy link
Contributor

Choose a reason for hiding this comment

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

You could use r"'\''"

Copy link
Contributor

@sigurdm sigurdm left a comment

Choose a reason for hiding this comment

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

LGTM

@jonasfj jonasfj merged commit 154a141 into dart-lang:master Mar 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement proper shell escaping for pub command error reproduction
3 participants