bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#8531: 24.0.50; shell-quote-argument shouldn't escape special charact


From: samer
Subject: bug#8531: 24.0.50; shell-quote-argument shouldn't escape special characters
Date: Mon, 08 Dec 2014 08:48:15 -0800
User-agent: Roundcube Webmail/0.9.5

Hi,

I found this bug on debbugs thanks to Lars' getting started guide. This change simplifies the code by making the behavior that used occur for newlines following a backslash, returning the character literal after the backslash, the behavior that occurs for _all_ non-special characters.

This is my first contribution to emacs, so don't hesitate to correct anything nonstandard in the patch I've included. I'm interested in doing more work on eshell, too. What eshell bugs would benefit from a fresh pair of eyes?

Also, I sent this email to 8531@debbugs.gnu.org five hours and I didn't see my email on debbugs. Apologies for the duplication if that email actually went through.

Best,
Samer

Patch for esh-arg.el:

*** /home/samer/build/emacs120714/share/emacs/25.0.50/lisp/eshell/esh-arg.el.gz.old --- /home/samer/build/emacs120714/share/emacs/25.0.50/lisp/eshell/esh-arg.el.gz
***************
*** 89,95 ****
          (goto-char (match-end 0))
          (eshell-finish-arg)))))

!    ;; backslash before a special character means escape it
     'eshell-parse-backslash

     ;; text beginning with ' is a literally quoted
--- 89,96 ----
          (goto-char (match-end 0))
          (eshell-finish-arg)))))

!    ;; backslash before a character escapes it if the character is
!    ;; special, and returns the character literal if it is non-special
     'eshell-parse-backslash

     ;; text beginning with ' is a literally quoted
***************
*** 282,294 ****
"A stub function that generates an error if a floating operator is found."
    (error "Unhandled operator in input text"))

- (defsubst eshell-looking-at-backslash-return (pos)
-   "Test whether a backslash-return sequence occurs at POS."
-   (and (eq (char-after pos) ?\\)
-        (or (= (1+ pos) (point-max))
-          (and (eq (char-after (1+ pos)) ?\n)
-               (= (+ pos 2) (point-max))))))
-
  (defun eshell-quote-backslash (string &optional index)
    "Intelligently backslash the character occurring in STRING at INDEX.
  If the character is itself a backslash, it needs no escaping."
--- 283,288 ----
***************
*** 305,313 ****
          (string ?\\ char)))))

  (defun eshell-parse-backslash ()
!   "Parse a single backslash (\) character, which might mean escape.
! It only means escape if the character immediately following is a
! special character that is not itself a backslash."
    (when (eq (char-after) ?\\)
      (if (eshell-looking-at-backslash-return (point))
        (throw 'eshell-incomplete ?\\)
--- 299,309 ----
          (string ?\\ char)))))

  (defun eshell-parse-backslash ()
! "Parse a single backslash (\) character to escape the character after.
! If the character immediately following the backslash is a special
! character, it returns the escaped version of that character.
! Else, the character has no meaning and is returned as the literal
! character. This conforms with the behavior of bash."
    (when (eq (char-after) ?\\)
      (if (eshell-looking-at-backslash-return (point))
        (throw 'eshell-incomplete ?\\)
***************
*** 321,338 ****
            (forward-char 2)
            (list 'eshell-escape-arg
                  (char-to-string (char-before))))
-       ;; allow \\<RET> to mean a literal "\" character followed by a
-       ;; normal return, rather than a backslash followed by a line
-       ;; continuation (i.e., "\\ + \n" rather than "\ + \\n").  This
-       ;; is necessary because backslashes in Eshell are not special
-       ;; unless they either precede something special, or precede a
-       ;; backslash that precedes something special.  (Mainly this is
-       ;; done to make using backslash on Windows systems more
-       ;; natural-feeling).
-       (if (eshell-looking-at-backslash-return (1+ (point)))
-           (forward-char))
        (forward-char)
!       "\\"))))

  (defun eshell-parse-literal-quote ()
    "Parse a literally quoted string.  Nothing has special meaning!"
--- 317,325 ----
            (forward-char 2)
            (list 'eshell-escape-arg
                  (char-to-string (char-before))))
        (forward-char)
!       (forward-char)
!       (char-before)))))

  (defun eshell-parse-literal-quote ()
    "Parse a literally quoted string.  Nothing has special meaning!"

Diff finished.  Mon Dec  8 01:23:11 2014
*** /home/samer/build/emacs120714/share/emacs/25.0.50/lisp/eshell/esh-arg.el.gz.old --- /home/samer/build/emacs120714/share/emacs/25.0.50/lisp/eshell/esh-arg.el.gz
***************
*** 89,95 ****
          (goto-char (match-end 0))
          (eshell-finish-arg)))))

!    ;; backslash before a special character means escape it
     'eshell-parse-backslash

     ;; text beginning with ' is a literally quoted
--- 89,96 ----
          (goto-char (match-end 0))
          (eshell-finish-arg)))))

!    ;; backslash before a character escapes it if the character is
!    ;; special, and returns the character literal if it is non-special
     'eshell-parse-backslash

     ;; text beginning with ' is a literally quoted
***************
*** 282,294 ****
"A stub function that generates an error if a floating operator is found."
    (error "Unhandled operator in input text"))

- (defsubst eshell-looking-at-backslash-return (pos)
-   "Test whether a backslash-return sequence occurs at POS."
-   (and (eq (char-after pos) ?\\)
-        (or (= (1+ pos) (point-max))
-          (and (eq (char-after (1+ pos)) ?\n)
-               (= (+ pos 2) (point-max))))))
-
  (defun eshell-quote-backslash (string &optional index)
    "Intelligently backslash the character occurring in STRING at INDEX.
  If the character is itself a backslash, it needs no escaping."
--- 283,288 ----
***************
*** 305,313 ****
          (string ?\\ char)))))

  (defun eshell-parse-backslash ()
!   "Parse a single backslash (\) character, which might mean escape.
! It only means escape if the character immediately following is a
! special character that is not itself a backslash."
    (when (eq (char-after) ?\\)
      (if (eshell-looking-at-backslash-return (point))
        (throw 'eshell-incomplete ?\\)
--- 299,309 ----
          (string ?\\ char)))))

  (defun eshell-parse-backslash ()
! "Parse a single backslash (\) character to escape the character after.
! If the character immediately following the backslash is a special
! character, it returns the escaped version of that character.
! Else, the character has no meaning and is returned as the literal
! character. This conforms with the behavior of bash."
    (when (eq (char-after) ?\\)
      (if (eshell-looking-at-backslash-return (point))
        (throw 'eshell-incomplete ?\\)
***************
*** 321,338 ****
            (forward-char 2)
            (list 'eshell-escape-arg
                  (char-to-string (char-before))))
-       ;; allow \\<RET> to mean a literal "\" character followed by a
-       ;; normal return, rather than a backslash followed by a line
-       ;; continuation (i.e., "\\ + \n" rather than "\ + \\n").  This
-       ;; is necessary because backslashes in Eshell are not special
-       ;; unless they either precede something special, or precede a
-       ;; backslash that precedes something special.  (Mainly this is
-       ;; done to make using backslash on Windows systems more
-       ;; natural-feeling).
-       (if (eshell-looking-at-backslash-return (1+ (point)))
-           (forward-char))
        (forward-char)
!       "\\"))))

  (defun eshell-parse-literal-quote ()
    "Parse a literally quoted string.  Nothing has special meaning!"
--- 317,325 ----
            (forward-char 2)
            (list 'eshell-escape-arg
                  (char-to-string (char-before))))
        (forward-char)
!       (forward-char)
!       (char-before)))))

  (defun eshell-parse-literal-quote ()
    "Parse a literally quoted string.  Nothing has special meaning!"





reply via email to

[Prev in Thread] Current Thread [Next in Thread]