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
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
9 changes: 7 additions & 2 deletions lib/src/command_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,13 @@ class PubCommandRunner extends CommandRunner {
if (topLevelResults['trace']) {
log.dumpTranscript();
} else if (!isUserFacingException(error)) {
// TODO(23505): Implement proper shell escaping, not a partial hack.
protectArgument(String x) => x.contains(' ') ? '"$x"' : x;
// Escape the argument for users to copy-paste in bash.
// Wrap with single quotation, and use '\'' to insert single quote, as
// long as we have no spaces this doesn't create a new argument.
protectArgument(String x) =>
RegExp(r'^[a-zA-Z0-9-_]+$').stringMatch(x) == null
? "'${x.replaceAll("'", r"'\''")}'"
: x;
log.error("""
This is an unexpected error. Please run

Expand Down