|
@@ -166,15 +166,28 @@ func (sw *shellWord) processStopOn(stopChar rune) (string, []string, error) {
|
|
|
func (sw *shellWord) processSingleQuote() (string, error) {
|
|
|
// All chars between single quotes are taken as-is
|
|
|
// Note, you can't escape '
|
|
|
+ //
|
|
|
+ // From the "sh" man page:
|
|
|
+ // Single Quotes
|
|
|
+ // Enclosing characters in single quotes preserves the literal meaning of
|
|
|
+ // all the characters (except single quotes, making it impossible to put
|
|
|
+ // single-quotes in a single-quoted string).
|
|
|
+
|
|
|
var result string
|
|
|
|
|
|
sw.scanner.Next()
|
|
|
|
|
|
for {
|
|
|
ch := sw.scanner.Next()
|
|
|
- if ch == '\'' || ch == scanner.EOF {
|
|
|
+
|
|
|
+ if ch == scanner.EOF {
|
|
|
+ return "", fmt.Errorf("unexpected end of statement while looking for matching single-quote")
|
|
|
+ }
|
|
|
+
|
|
|
+ if ch == '\'' {
|
|
|
break
|
|
|
}
|
|
|
+
|
|
|
result += string(ch)
|
|
|
}
|
|
|
|
|
@@ -184,16 +197,32 @@ func (sw *shellWord) processSingleQuote() (string, error) {
|
|
|
func (sw *shellWord) processDoubleQuote() (string, error) {
|
|
|
// All chars up to the next " are taken as-is, even ', except any $ chars
|
|
|
// But you can escape " with a \ (or ` if escape token set accordingly)
|
|
|
+ //
|
|
|
+ // From the "sh" man page:
|
|
|
+ // Double Quotes
|
|
|
+ // Enclosing characters within double quotes preserves the literal meaning
|
|
|
+ // of all characters except dollarsign ($), backquote (`), and backslash
|
|
|
+ // (\). The backslash inside double quotes is historically weird, and
|
|
|
+ // serves to quote only the following characters:
|
|
|
+ // $ ` " \ <newline>.
|
|
|
+ // Otherwise it remains literal.
|
|
|
+
|
|
|
var result string
|
|
|
|
|
|
sw.scanner.Next()
|
|
|
|
|
|
- for sw.scanner.Peek() != scanner.EOF {
|
|
|
+ for {
|
|
|
ch := sw.scanner.Peek()
|
|
|
+
|
|
|
+ if ch == scanner.EOF {
|
|
|
+ return "", fmt.Errorf("unexpected end of statement while looking for matching double-quote")
|
|
|
+ }
|
|
|
+
|
|
|
if ch == '"' {
|
|
|
sw.scanner.Next()
|
|
|
break
|
|
|
}
|
|
|
+
|
|
|
if ch == '$' {
|
|
|
tmp, err := sw.processDollar()
|
|
|
if err != nil {
|
|
@@ -210,8 +239,11 @@ func (sw *shellWord) processDoubleQuote() (string, error) {
|
|
|
continue
|
|
|
}
|
|
|
|
|
|
- if chNext == '"' || chNext == '$' {
|
|
|
- // \" and \$ can be escaped, all other \'s are left as-is
|
|
|
+ // Note: for now don't do anything special with ` chars.
|
|
|
+ // Not sure what to do with them anyway since we're not going
|
|
|
+ // to execute the text in there (not now anyway).
|
|
|
+ if chNext == '"' || chNext == '$' || chNext == sw.escapeToken {
|
|
|
+ // These chars can be escaped, all other \'s are left as-is
|
|
|
ch = sw.scanner.Next()
|
|
|
}
|
|
|
}
|