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(