Repository: asottile/pyupgrade

Issue:
Error after upgrading a formatted sting starting with a variable
If I run pyupgrade on this string : 
  **'{}\N{NO-BREAK SPACE}'.format(currency.symbol or "")**
I get this line as an output : 
"\N{NO-BREAK SPACE}".format(currency.symbol or "") 
Wich causes an error 

Discussion:

Patch:
diff --git a/pyupgrade/_string_helpers.py b/pyupgrade/_string_helpers.py
index 4271839..1c15655 100644
--- a/pyupgrade/_string_helpers.py
+++ b/pyupgrade/_string_helpers.py
@@ -19,7 +19,7 @@ def parse_format(s: str) -> list[DotFormatPart]:
 
     for part in NAMED_UNICODE_RE.split(s):
         if NAMED_UNICODE_RE.fullmatch(part):
-            if not ret:
+            if not ret or ret[-1][1:] != (None, None, None):
                 ret.append((part, None, None, None))
             else:
                 ret[-1] = (ret[-1][0] + part, None, None, None)


Test patch:
diff --git a/tests/features/format_literals_test.py b/tests/features/format_literals_test.py
index aaa6ef0..837e593 100644
--- a/tests/features/format_literals_test.py
+++ b/tests/features/format_literals_test.py
@@ -25,6 +25,8 @@ from pyupgrade._main import _fix_tokens
         '("{0}" # {1}\n"{2}").format(1, 2, 3)',
         # don't touch f-strings (these are wrong but don't make it worse)
         'f"{0}".format(a)',
+        # shouldn't touch the format spec
+        r'"{}\N{SNOWMAN}".format("")',
     ),
 )
 def test_format_literals_noop(s):