[PATCH 1 of 2] windows: add doctest for shellquote()

Matt Harbison mharbison72 at gmail.com
Sat May 2 02:57:19 UTC 2015


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1430525820 14400
#      Fri May 01 20:17:00 2015 -0400
# Node ID 95f85481cf53e0855e9481fbd85196efcaa72455
# Parent  e9edd53770fb77a9787a3e6592a3bf0a29c1bd80
windows: add doctest for shellquote()

This is actual test coverage for issue4629.  The test changes in eea3977e6fca
were simply the addition of quotes to the output, not ensuring that strings with
backslashes are quoted.

diff --git a/mercurial/windows.py b/mercurial/windows.py
--- a/mercurial/windows.py
+++ b/mercurial/windows.py
@@ -162,6 +162,18 @@
 _quotere = None
 _needsshellquote = None
 def shellquote(s):
+    r"""
+    >>> shellquote(r'C:\Users\xyz')
+    '"C:\\Users\\xyz"'
+    >>> shellquote(r'C:\Users\xyz/mixed')
+    '"C:\\Users\\xyz/mixed"'
+    >>> # Would be safe not to quote too, since it is all double backslashes
+    >>> shellquote(r'C:\\Users\\xyz')
+    '"C:\\\\Users\\\\xyz"'
+    >>> # But this must be quoted
+    >>> shellquote(r'C:\\Users\\xyz/abc')
+    '"C:\\\\Users\\\\xyz/abc"'
+    """
     global _quotere
     if _quotere is None:
         _quotere = re.compile(r'(\\*)("|\\$)')


More information about the Mercurial-devel mailing list