Commits

guillermooo committed c4c6de7

enable use of double quotes in user-supplied input

Escaping of double quotes in user-supplied input is fragile, but should
cover most cases.

  • Participants
  • Parent commits 086585f

Comments (0)

Files changed (4)

+12.9.27
+	- enable use of double quotes in user-supplied input
 12.6.8
 	- add command to kill servers
 	- improve error handling when current view does not belong to any repo
 # encoding: utf-8
 
-PACKAGE_VERSION = "12.7.18"
+PACKAGE_VERSION = "12.9.27"
 
 """Commands to build and manage .sublime-package archives with distutils."""
 

shglib/parsing.py

 
     def _STRING(self):
         delimiter = self.c
+        str_buf = []
         self.consume()
-        str_buf = []
         while self.c != EOF:
             if self.c == '\\':
+                self.consume()
+                if self.c == delimiter:
+                    str_buf.append(self.c)
+                    self.consume()
+                else:
+                    str_buf.append('\\')
+                    str_buf.append(self.c)
+                    self.consume()
+            else:
                 str_buf.append(self.c)
                 self.consume()
-                if self.c == EOF or self.c not in (delimiter, '\\'):
-                    SyntaxError("expected escape sequence, got '\\%s'" % self.c)
-            str_buf.append(self.c)
-            self.consume()
             if self.c == delimiter:
                 self.consume()
                 break
         while self.c != EOF:
             if self.c in self._white_space:
                 self._WHITE_SPACE()
-            # elif self.c.isalpha() and self.status != self._in_option:
-            #     yield self._NAME()
             elif self.c == '-':
                 yield self._OPTION()
             elif self.c in '\'"':
 
 
 if __name__ == '__main__':
-    # lx = Lexer(" foo")
-    # while lx.c != EOF:
-    #     print lx.c
-    #     lx.consume()
+    # todo: add tests
     values = (
             "foo",
             "foo -b",
             "foo -b 'this is a string' --cmd \"whatever and ever\"",
             "foo -b 'this is \\'a string'",
             "foo -b 'mañana será otro día'",
+            "commit -m 'there are \" some things here'",
+            "commit -m 'there are \u some things here'",
             "locate ut*.py",
         )
     for v in values:
 import functools
 import subprocess
 import os
+import re
 
 from shglib import commands
 from shglib import utils
         raise NotImplementedError("Cannot run consoles in OS X. Not implemented.")
 
 
+def escape(s, c, esc='\\\\'):
+    # FIXME: won't escape \\" and such correctly.
+    pat = "(?<!%s)%s" % (esc, c)
+    r = re.compile(pat)
+    return r.sub(esc + c, s)
+
+
 class CommandRunnerWorker(threading.Thread):
     """Runs the Mercurial command and reports the output.
     """
                                                                 self.content})
 
     def on_done(self, s):
-        self.content['input'] = s
+        self.content['input'] = escape(s, '"')
         self.view.run_command("hg_command_runner", {"cmd": self.fmtstr %
                                                                 self.content})