]> git.madduck.net Git - etc/vim.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Fix string normalization eating all backslashes above 3
authorZsolt Dollenstein <zsol.zsol@gmail.com>
Sun, 10 Jun 2018 08:39:24 +0000 (09:39 +0100)
committerZsolt Dollenstein <zsol.zsol@gmail.com>
Sun, 10 Jun 2018 08:44:41 +0000 (09:44 +0100)
README.md
black.py
tests/data/string_quotes.py
tests/data/string_wayne.py [deleted file]

index 67cd613cb62b356239971d617179dbb4fdd1bed1..0f2248273d5bc72ef9f85fc5020cbb2eeef1ab04 100644 (file)
--- a/README.md
+++ b/README.md
@@ -816,6 +816,8 @@ More details can be found in [CONTRIBUTING](CONTRIBUTING.md).
 
 * fixed unnecessary slowdown on AST nodes with very many siblings
 
 
 * fixed unnecessary slowdown on AST nodes with very many siblings
 
+* fixed cannibalizing backslashes during string normalization
+
 
 ### 18.6b2
 
 
 ### 18.6b2
 
index a405bada1358344db949664afd3e041432554b9f..9d9bada604951bef5bc9afca90033a31411c260e 100644 (file)
--- a/black.py
+++ b/black.py
@@ -2529,8 +2529,8 @@ def normalize_string_quotes(leaf: Leaf) -> None:
 
     prefix = leaf.value[:first_quote_pos]
     unescaped_new_quote = re.compile(rf"(([^\\]|^)(\\\\)*){new_quote}")
 
     prefix = leaf.value[:first_quote_pos]
     unescaped_new_quote = re.compile(rf"(([^\\]|^)(\\\\)*){new_quote}")
-    escaped_new_quote = re.compile(rf"([^\\]|^)\\(\\\\)*{new_quote}")
-    escaped_orig_quote = re.compile(rf"([^\\]|^)\\(\\\\)*{orig_quote}")
+    escaped_new_quote = re.compile(rf"([^\\]|^)\\((?:\\\\)*){new_quote}")
+    escaped_orig_quote = re.compile(rf"([^\\]|^)\\((?:\\\\)*){orig_quote}")
     body = leaf.value[first_quote_pos + len(orig_quote) : -len(orig_quote)]
     if "r" in prefix.casefold():
         if unescaped_new_quote.search(body):
     body = leaf.value[first_quote_pos + len(orig_quote) : -len(orig_quote)]
     if "r" in prefix.casefold():
         if unescaped_new_quote.search(body):
@@ -2541,10 +2541,10 @@ def normalize_string_quotes(leaf: Leaf) -> None:
         # Do not introduce or remove backslashes in raw strings
         new_body = body
     else:
         # Do not introduce or remove backslashes in raw strings
         new_body = body
     else:
-        # remove unnecessary quotes
+        # remove unnecessary escapes
         new_body = sub_twice(escaped_new_quote, rf"\1\2{new_quote}", body)
         if body != new_body:
         new_body = sub_twice(escaped_new_quote, rf"\1\2{new_quote}", body)
         if body != new_body:
-            # Consider the string without unnecessary quotes as the original
+            # Consider the string without unnecessary escapes as the original
             body = new_body
             leaf.value = f"{prefix}{orig_quote}{body}{orig_quote}"
         new_body = sub_twice(escaped_orig_quote, rf"\1\2{orig_quote}", new_body)
             body = new_body
             leaf.value = f"{prefix}{orig_quote}{body}{orig_quote}"
         new_body = sub_twice(escaped_orig_quote, rf"\1\2{orig_quote}", new_body)
index 807f8669f5a647b9cbf2535aa0e844d7115a8858..1994dd273d92b5a9936ab22f76492a2bc1347141 100644 (file)
@@ -43,6 +43,7 @@ re.compile(r'[\\"]')
 "unnecessary \'\'escaping"
 '\\""'
 "\\''"
 "unnecessary \'\'escaping"
 '\\""'
 "\\''"
+'Lots of \\\\\\\\\'quotes\''
 
 # output
 
 
 # output
 
@@ -91,3 +92,4 @@ re.compile(r'[\\"]')
 "unnecessary ''escaping"
 '\\""'
 "\\''"
 "unnecessary ''escaping"
 '\\""'
 "\\''"
+"Lots of \\\\\\\\'quotes'"
diff --git a/tests/data/string_wayne.py b/tests/data/string_wayne.py
deleted file mode 100644 (file)
index 702349e..0000000
+++ /dev/null
@@ -1 +0,0 @@
-u'"Based on the Saturday Night Live sketch of the same name, Wayne\'s World is a wacky, irreverent pop culture comedy about the adventures of two amiably aimless metal head friends, Wayne (Mike Myers) and Garth (Dana Carvey). From Wayne\'s basement, the pair broadcast a talk show called \\\\"Wayne\'s World\\\\" on local public access television. The show comes to the attention of a sleazy network executive (Rob Lowe) who wants to produce a big budget version of \\\\"Wayne\'s World\\\\" and he also wants Wayne\'s girlfriend, a rock singer named Cassandra (Tia Carrere). Wayne and Garth have to battle the executive not only to save their show, but also Cassandra. Director Penelope Spheeris, Myers and Carvey hang a lot of silly, but funny, jokes on this thin plot, and the energy of the cast as well as the wild pop culture references make Wayne\'s World a cut above the average Saturday Night Live spin off movie.\\\\n"'