mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:24 +00:00
Normalise Hex and unicode escape sequences in string (#9280)
This commit is contained in:
parent
c716acc7a6
commit
5d4825b60f
10 changed files with 263 additions and 113 deletions
|
@ -1,97 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/cases/preview_format_unicode_escape_seq.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```python
|
||||
x = "\x1F"
|
||||
x = "\\x1B"
|
||||
x = "\\\x1B"
|
||||
x = "\U0001F60E"
|
||||
x = "\u0001F60E"
|
||||
x = r"\u0001F60E"
|
||||
x = "don't format me"
|
||||
x = "\xA3"
|
||||
x = "\u2717"
|
||||
x = "\uFaCe"
|
||||
x = "\N{ox}\N{OX}"
|
||||
x = "\N{lAtIn smaLL letteR x}"
|
||||
x = "\N{CYRILLIC small LETTER BYELORUSSIAN-UKRAINIAN I}"
|
||||
x = b"\x1Fdon't byte"
|
||||
x = rb"\x1Fdon't format"
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,15 +1,15 @@
|
||||
-x = "\x1f"
|
||||
+x = "\x1F"
|
||||
x = "\\x1B"
|
||||
-x = "\\\x1b"
|
||||
-x = "\U0001f60e"
|
||||
+x = "\\\x1B"
|
||||
+x = "\U0001F60E"
|
||||
x = "\u0001F60E"
|
||||
x = r"\u0001F60E"
|
||||
x = "don't format me"
|
||||
-x = "\xa3"
|
||||
+x = "\xA3"
|
||||
x = "\u2717"
|
||||
-x = "\uface"
|
||||
-x = "\N{OX}\N{OX}"
|
||||
-x = "\N{LATIN SMALL LETTER X}"
|
||||
-x = "\N{CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN I}"
|
||||
-x = b"\x1fdon't byte"
|
||||
+x = "\uFaCe"
|
||||
+x = "\N{ox}\N{OX}"
|
||||
+x = "\N{lAtIn smaLL letteR x}"
|
||||
+x = "\N{CYRILLIC small LETTER BYELORUSSIAN-UKRAINIAN I}"
|
||||
+x = b"\x1Fdon't byte"
|
||||
x = rb"\x1Fdon't format"
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```python
|
||||
x = "\x1F"
|
||||
x = "\\x1B"
|
||||
x = "\\\x1B"
|
||||
x = "\U0001F60E"
|
||||
x = "\u0001F60E"
|
||||
x = r"\u0001F60E"
|
||||
x = "don't format me"
|
||||
x = "\xA3"
|
||||
x = "\u2717"
|
||||
x = "\uFaCe"
|
||||
x = "\N{ox}\N{OX}"
|
||||
x = "\N{lAtIn smaLL letteR x}"
|
||||
x = "\N{CYRILLIC small LETTER BYELORUSSIAN-UKRAINIAN I}"
|
||||
x = b"\x1Fdon't byte"
|
||||
x = rb"\x1Fdon't format"
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```python
|
||||
x = "\x1f"
|
||||
x = "\\x1B"
|
||||
x = "\\\x1b"
|
||||
x = "\U0001f60e"
|
||||
x = "\u0001F60E"
|
||||
x = r"\u0001F60E"
|
||||
x = "don't format me"
|
||||
x = "\xa3"
|
||||
x = "\u2717"
|
||||
x = "\uface"
|
||||
x = "\N{OX}\N{OX}"
|
||||
x = "\N{LATIN SMALL LETTER X}"
|
||||
x = "\N{CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN I}"
|
||||
x = b"\x1fdon't byte"
|
||||
x = rb"\x1Fdon't format"
|
||||
```
|
||||
|
||||
|
|
@ -124,6 +124,8 @@ test_particular = [
|
|||
b'c'
|
||||
)
|
||||
}
|
||||
|
||||
b"Unicode Escape sequence don't apply to bytes: \N{0x} \u{ABCD} \U{ABCDEFGH}"
|
||||
```
|
||||
|
||||
## Outputs
|
||||
|
@ -277,6 +279,8 @@ test_particular = [
|
|||
|
||||
# Parenthesized string continuation with messed up indentation
|
||||
{"key": ([], b"a" b"b" b"c")}
|
||||
|
||||
b"Unicode Escape sequence don't apply to bytes: \N{0x} \u{ABCD} \U{ABCDEFGH}"
|
||||
```
|
||||
|
||||
|
||||
|
@ -430,6 +434,8 @@ test_particular = [
|
|||
|
||||
# Parenthesized string continuation with messed up indentation
|
||||
{'key': ([], b'a' b'b' b'c')}
|
||||
|
||||
b"Unicode Escape sequence don't apply to bytes: \N{0x} \u{ABCD} \U{ABCDEFGH}"
|
||||
```
|
||||
|
||||
|
||||
|
|
|
@ -139,6 +139,11 @@ x = (b"""aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa""" b"""bbbbbbbbbbbbbbbbbbbbbbbbbbb
|
|||
|
||||
# https://github.com/astral-sh/ruff/issues/7460
|
||||
trailing_preferred_quote_texts = [''' "''', ''' ""''', ''' """''', ''' """"''']
|
||||
|
||||
a = f"""\x1F"""
|
||||
a = """\x1F"""
|
||||
a = """\\x1F"""
|
||||
a = """\\\x1F"""
|
||||
```
|
||||
|
||||
## Outputs
|
||||
|
@ -316,6 +321,11 @@ x = (
|
|||
|
||||
# https://github.com/astral-sh/ruff/issues/7460
|
||||
trailing_preferred_quote_texts = [''' "''', ''' ""''', ''' """''', ''' """"''']
|
||||
|
||||
a = f"""\x1F"""
|
||||
a = """\x1F"""
|
||||
a = """\\x1F"""
|
||||
a = """\\\x1F"""
|
||||
```
|
||||
|
||||
|
||||
|
@ -329,6 +339,17 @@ trailing_preferred_quote_texts = [''' "''', ''' ""''', ''' """''', ''' """"''']
|
|||
'" test'
|
||||
|
||||
'" test'
|
||||
@@ -158,7 +159,7 @@
|
||||
# https://github.com/astral-sh/ruff/issues/7460
|
||||
trailing_preferred_quote_texts = [''' "''', ''' ""''', ''' """''', ''' """"''']
|
||||
|
||||
-a = f"""\x1F"""
|
||||
-a = """\x1F"""
|
||||
+a = f"""\x1f"""
|
||||
+a = """\x1f"""
|
||||
a = """\\x1F"""
|
||||
-a = """\\\x1F"""
|
||||
+a = """\\\x1f"""
|
||||
```
|
||||
|
||||
|
||||
|
@ -506,6 +527,11 @@ x = (
|
|||
|
||||
# https://github.com/astral-sh/ruff/issues/7460
|
||||
trailing_preferred_quote_texts = [''' "''', ''' ""''', ''' """''', ''' """"''']
|
||||
|
||||
a = f"""\x1F"""
|
||||
a = """\x1F"""
|
||||
a = """\\x1F"""
|
||||
a = """\\\x1F"""
|
||||
```
|
||||
|
||||
|
||||
|
@ -519,6 +545,17 @@ trailing_preferred_quote_texts = [''' "''', ''' ""''', ''' """''', ''' """"''']
|
|||
'" test'
|
||||
|
||||
'" test'
|
||||
@@ -158,7 +159,7 @@
|
||||
# https://github.com/astral-sh/ruff/issues/7460
|
||||
trailing_preferred_quote_texts = [''' "''', ''' ""''', ''' """''', ''' """"''']
|
||||
|
||||
-a = f"""\x1F"""
|
||||
-a = """\x1F"""
|
||||
+a = f"""\x1f"""
|
||||
+a = """\x1f"""
|
||||
a = """\\x1F"""
|
||||
-a = """\\\x1F"""
|
||||
+a = """\\\x1f"""
|
||||
```
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue