From 4ca226b7f46c13295a772fc8f9022a9943612148 Mon Sep 17 00:00:00 2001 From: Zanie Date: Wed, 16 Aug 2023 14:26:47 -0500 Subject: [PATCH] Tweak `right` slice after split --- crates/ruff_python_literal/src/format.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/ruff_python_literal/src/format.rs b/crates/ruff_python_literal/src/format.rs index 96f724ad2c8504..4d34f96bb0bf80 100644 --- a/crates/ruff_python_literal/src/format.rs +++ b/crates/ruff_python_literal/src/format.rs @@ -1078,9 +1078,9 @@ impl FormatString { left.push(c); continue; } - let (_, right) = text.split_at(idx); + let (_, right) = text.split_at(idx + 1); let format_part = FormatString::parse_part_in_brackets(&left)?; - return Ok((format_part, &right[1..])); + return Ok((format_part, &right)); } else { left.push(c); } @@ -1478,6 +1478,10 @@ mod tests { FormatSpec::parse("}"), Err(FormatSpecError::InvalidFormatType) ); + assert_eq!( + FormatSpec::parse("{}}"), + Err(FormatSpecError::InvalidFormatType) + ); assert_eq!( FormatSpec::parse("{{x}}"), Err(FormatSpecError::InvalidPlaceholder(