Skip to content

Commit

Permalink
Fix PLE251 rules with f-string escaping
Browse files Browse the repository at this point in the history
**Summary** The `value` of the `FStringMiddle` for `f"""}}a�b"""` is `}a�b`, i.e. the curly brace escaping is decoded. If we iterate over string this gives us false indices causing exploding fixes for PLE251 rules (PLE2510, PLE2512, PLE2513, PLE2514, PLE2515). Instead, we now use the source range.

Handles #7455 (comment)
Handles #7455 (comment)

**Test Plan** Minimized fuzzing cases as fixtures.
  • Loading branch information
konstin committed Oct 1, 2023
1 parent 2838f7a commit 539e337
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ pub(crate) fn invalid_string_characters(
) {
let text = match tok {
Tok::String { .. } => locator.slice(range),
Tok::FStringMiddle { value, .. } => value.as_str(),
// The string value has already decoded escaped curly braces, which would gives us wrong
// column information
Tok::FStringMiddle { .. } => &locator.contents()[range],
_ => return,
};

Expand Down

0 comments on commit 539e337

Please sign in to comment.