Skip to content

Commit 154a141

Browse files
authored
Fix #28 -- escaping arguments as mentioned in TODO (#2093)
1 parent bb2b8b2 commit 154a141

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/src/command_runner.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,13 @@ class PubCommandRunner extends CommandRunner {
180180
if (topLevelResults['trace']) {
181181
log.dumpTranscript();
182182
} else if (!isUserFacingException(error)) {
183-
// TODO(23505): Implement proper shell escaping, not a partial hack.
184-
protectArgument(String x) => x.contains(' ') ? '"$x"' : x;
183+
// Escape the argument for users to copy-paste in bash.
184+
// Wrap with single quotation, and use '\'' to insert single quote, as
185+
// long as we have no spaces this doesn't create a new argument.
186+
protectArgument(String x) =>
187+
RegExp(r'^[a-zA-Z0-9-_]+$').stringMatch(x) == null
188+
? "'${x.replaceAll("'", r"'\''")}'"
189+
: x;
185190
log.error("""
186191
This is an unexpected error. Please run
187192

0 commit comments

Comments
 (0)