forked from Rust-related/RustPython
Fix panic when parsing a format spec with multi-byte character
This commit is contained in:
@@ -869,7 +869,7 @@ impl FormatString {
|
||||
let mut left = String::new();
|
||||
|
||||
// There may be one layer nesting brackets in spec
|
||||
for (idx, c) in text.chars().enumerate() {
|
||||
for (idx, c) in text.char_indices() {
|
||||
if idx == 0 {
|
||||
if c != '{' {
|
||||
return Err(FormatParseError::MissingStartBracket);
|
||||
@@ -1076,6 +1076,11 @@ mod tests {
|
||||
assert_eq!(FormatString::from_str("abcd{1}:{key}"), expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_parse_multi_byte_char() {
|
||||
assert!(FormatString::from_str("{a:%ЫйЯЧ}").is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_parse_fail() {
|
||||
assert_eq!(
|
||||
|
||||
Reference in New Issue
Block a user