Skip to content

Commit 68d413e

Browse files
authored
Merge pull request RustPython#4444 from messense/fix-format-spec-multi-byte
Fix panic when parsing a format spec with multi-byte character
2 parents 91a897d + ee5a1c9 commit 68d413e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

common/src/format.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ impl FormatString {
869869
let mut left = String::new();
870870

871871
// There may be one layer nesting brackets in spec
872-
for (idx, c) in text.chars().enumerate() {
872+
for (idx, c) in text.char_indices() {
873873
if idx == 0 {
874874
if c != '{' {
875875
return Err(FormatParseError::MissingStartBracket);
@@ -1076,6 +1076,11 @@ mod tests {
10761076
assert_eq!(FormatString::from_str("abcd{1}:{key}"), expected);
10771077
}
10781078

1079+
#[test]
1080+
fn test_format_parse_multi_byte_char() {
1081+
assert!(FormatString::from_str("{a:%ЫйЯЧ}").is_ok());
1082+
}
1083+
10791084
#[test]
10801085
fn test_format_parse_fail() {
10811086
assert_eq!(

0 commit comments

Comments
 (0)