mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-24 05:25:17 +00:00
Fix formatting of trailing unescaped quotes in raw triple quoted strings (#6202)
**Summary** This prevents us from turning `r'''\""'''` into `r"""\"""""`, which is invalid syntax. This PR fixes CI, which is currently broken on main (in a way that still passes on linter PRs and allows merging formatter PRs, but it's bad to have a job be red). Once merged, i'll make the formatted ecosystem checks a required check. **Test Plan** Added a regression test.
This commit is contained in:
parent
dbd60b2cf5
commit
9063f4524d
3 changed files with 37 additions and 6 deletions
|
@ -24,6 +24,12 @@ U"Test"
|
||||||
r"Test"
|
r"Test"
|
||||||
R"Test"
|
R"Test"
|
||||||
|
|
||||||
|
# Block conversion if there is an unescaped quote just before the end of the triple
|
||||||
|
# quoted string
|
||||||
|
r'''\""'''
|
||||||
|
r'''""'''
|
||||||
|
r'\""'
|
||||||
|
|
||||||
'This string will not include \
|
'This string will not include \
|
||||||
backslashes or newline characters.'
|
backslashes or newline characters.'
|
||||||
|
|
||||||
|
|
|
@ -323,14 +323,21 @@ fn preferred_quotes_raw(
|
||||||
break true;
|
break true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if chars.peek() == Some(&configured_quote_char) {
|
match chars.peek() {
|
||||||
// `""` or `''`
|
// We can't turn `r'''\""'''` into `r"""\"""""`, this would confuse the parser
|
||||||
chars.next();
|
// about where the closing triple quotes start
|
||||||
|
None => break true,
|
||||||
|
Some(next) if *next == configured_quote_char => {
|
||||||
|
// `""` or `''`
|
||||||
|
chars.next();
|
||||||
|
|
||||||
if chars.peek() == Some(&configured_quote_char) {
|
// We can't turn `r'''""'''` into `r""""""""`, nor can we have
|
||||||
// `"""` or `'''`
|
// `"""` or `'''` respectively inside the string
|
||||||
break true;
|
if chars.peek().is_none() || chars.peek() == Some(&configured_quote_char) {
|
||||||
|
break true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(_) => continue,
|
Some(_) => continue,
|
||||||
|
|
|
@ -30,6 +30,12 @@ U"Test"
|
||||||
r"Test"
|
r"Test"
|
||||||
R"Test"
|
R"Test"
|
||||||
|
|
||||||
|
# Block conversion if there is an unescaped quote just before the end of the triple
|
||||||
|
# quoted string
|
||||||
|
r'''\""'''
|
||||||
|
r'''""'''
|
||||||
|
r'\""'
|
||||||
|
|
||||||
'This string will not include \
|
'This string will not include \
|
||||||
backslashes or newline characters.'
|
backslashes or newline characters.'
|
||||||
|
|
||||||
|
@ -162,6 +168,12 @@ magic-trailing-comma = Respect
|
||||||
r"Test"
|
r"Test"
|
||||||
R"Test"
|
R"Test"
|
||||||
|
|
||||||
|
# Block conversion if there is an unescaped quote just before the end of the triple
|
||||||
|
# quoted string
|
||||||
|
r'''\""'''
|
||||||
|
r'''""'''
|
||||||
|
r'\""'
|
||||||
|
|
||||||
"This string will not include \
|
"This string will not include \
|
||||||
backslashes or newline characters."
|
backslashes or newline characters."
|
||||||
|
|
||||||
|
@ -310,6 +322,12 @@ magic-trailing-comma = Respect
|
||||||
r'Test'
|
r'Test'
|
||||||
R'Test'
|
R'Test'
|
||||||
|
|
||||||
|
# Block conversion if there is an unescaped quote just before the end of the triple
|
||||||
|
# quoted string
|
||||||
|
r'''\""'''
|
||||||
|
r'''""'''
|
||||||
|
r'\""'
|
||||||
|
|
||||||
'This string will not include \
|
'This string will not include \
|
||||||
backslashes or newline characters.'
|
backslashes or newline characters.'
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue