Loading black.py +3 −0 Changes for black.py: 3 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -1998,6 +1998,9 @@ def normalize_string_quotes(leaf: Leaf) -> None: else: new_body = escaped_orig_quote.sub(rf"\1{orig_quote}", body) new_body = unescaped_new_quote.sub(rf"\1\\{new_quote}", new_body) # Add escapes again for consecutive occurences of new_quote (sub # doesn't match overlapping substrings). new_body = unescaped_new_quote.sub(rf"\1\\{new_quote}", new_body) if new_quote == '"""' and new_body[-1] == '"': # edge case: new_body = new_body[:-1] + '\\"' Loading tests/string_quotes.py +16 −0 Changes for tests/string_quotes.py: 16 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -30,6 +30,14 @@ the \'lazy\' dog.\n\ ' re.compile(r'[\\"]') "x = ''; y = \"\"" "x = '''; y = \"\"" "x = ''''; y = \"\"" "x = '' ''; y = \"\"" "x = ''; y = \"\"\"" "x = '''; y = \"\"\"\"" "x = ''''; y = \"\"\"\"\"" "x = '' ''; y = \"\"\"\"\"" # output Loading Loading @@ -65,3 +73,11 @@ the 'lazy' dog.\n\ " re.compile(r'[\\"]') "x = ''; y = \"\"" "x = '''; y = \"\"" "x = ''''; y = \"\"" "x = '' ''; y = \"\"" 'x = \'\'; y = """' 'x = \'\'\'; y = """"' 'x = \'\'\'\'; y = """""' 'x = \'\' \'\'; y = """""' Loading
black.py +3 −0 Changes for black.py: 3 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -1998,6 +1998,9 @@ def normalize_string_quotes(leaf: Leaf) -> None: else: new_body = escaped_orig_quote.sub(rf"\1{orig_quote}", body) new_body = unescaped_new_quote.sub(rf"\1\\{new_quote}", new_body) # Add escapes again for consecutive occurences of new_quote (sub # doesn't match overlapping substrings). new_body = unescaped_new_quote.sub(rf"\1\\{new_quote}", new_body) if new_quote == '"""' and new_body[-1] == '"': # edge case: new_body = new_body[:-1] + '\\"' Loading
tests/string_quotes.py +16 −0 Changes for tests/string_quotes.py: 16 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -30,6 +30,14 @@ the \'lazy\' dog.\n\ ' re.compile(r'[\\"]') "x = ''; y = \"\"" "x = '''; y = \"\"" "x = ''''; y = \"\"" "x = '' ''; y = \"\"" "x = ''; y = \"\"\"" "x = '''; y = \"\"\"\"" "x = ''''; y = \"\"\"\"\"" "x = '' ''; y = \"\"\"\"\"" # output Loading Loading @@ -65,3 +73,11 @@ the 'lazy' dog.\n\ " re.compile(r'[\\"]') "x = ''; y = \"\"" "x = '''; y = \"\"" "x = ''''; y = \"\"" "x = '' ''; y = \"\"" 'x = \'\'; y = """' 'x = \'\'\'; y = """"' 'x = \'\'\'\'; y = """""' 'x = \'\' \'\'; y = """""'