From b719975ae49d414f56a87133c3831b462be65ea8 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 0f75a6c08bdc7..5844eb5b4ee3f 100644 --- a/crates/ruff_python_literal/src/format.rs +++ b/crates/ruff_python_literal/src/format.rs @@ -659,9 +659,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); } @@ -961,6 +961,10 @@ mod tests { FormatSpec::parse("}"), Err(FormatSpecError::InvalidFormatType) ); + assert_eq!( + FormatSpec::parse("{}}"), + Err(FormatSpecError::InvalidFormatType) + ); assert_eq!( FormatSpec::parse("{{x}}"), Err(FormatSpecError::InvalidPlaceholder(