Skip to content

fix: escape # character to prevent shell comment interpretation#16

Open
Yanhu007 wants to merge 1 commit intokballard:masterfrom
Yanhu007:fix/escape-hash-comment
Open

fix: escape # character to prevent shell comment interpretation#16
Yanhu007 wants to merge 1 commit intokballard:masterfrom
Yanhu007:fix/escape-hash-comment

Conversation

@Yanhu007
Copy link
Copy Markdown

Fixes #15

Problem

shellquote.Join("cd", "#metoo") produces cd #metoo. When passed to /bin/sh, the #metoo part is interpreted as a comment and silently discarded:

shellquote.Join("cd", "#metoo")
// Output: cd #metoo
// Shell sees: cd (with a comment)

Fix

Add # to specialChars so it gets backslash-escaped:

shellquote.Join("cd", "#metoo")
// Output: cd \#metoo
// Shell sees: cd #metoo (correct)

All existing tests pass.

The # character starts a comment in shell when it appears at the
beginning of a word. shellquote.Join("cd", "#metoo") produced
"cd #metoo" which shell interprets as "cd" with a comment,
silently ignoring the argument.

Add # to specialChars so it gets backslash-escaped.

Fixes kballard#15
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.

it seems weird that comments do not get escaped

1 participant