From 61a032d7e2796f12859340a5f62b421e1f66dd51 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Tue, 16 Dec 2025 20:35:29 +0900 Subject: [PATCH] fix buffer --- .cspell.dict/cpython.txt | 3 +++ crates/vm/src/buffer.rs | 19 ++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/.cspell.dict/cpython.txt b/.cspell.dict/cpython.txt index 26921e04080..8acb1468f66 100644 --- a/.cspell.dict/cpython.txt +++ b/.cspell.dict/cpython.txt @@ -15,6 +15,7 @@ cellvar cellvars cmpop denom +DICTFLAG dictoffset elts excepthandler @@ -28,6 +29,7 @@ heaptype HIGHRES IMMUTABLETYPE Itertool +keeped kwonlyarg kwonlyargs lasti @@ -48,6 +50,7 @@ PYTHREAD_NAME SA_ONSTACK SOABI stackdepth +stginfo stringlib structseq subparams diff --git a/crates/vm/src/buffer.rs b/crates/vm/src/buffer.rs index 13cebfc6a28..cf49d6815c0 100644 --- a/crates/vm/src/buffer.rs +++ b/crates/vm/src/buffer.rs @@ -238,10 +238,23 @@ impl FormatCode { _ => 1, }; + // Skip whitespace (Python ignores whitespace in format strings) + while let Some(b' ' | b'\t' | b'\n' | b'\r') = chars.peek() { + chars.next(); + } + // determine format char: - let c = chars - .next() - .ok_or_else(|| "repeat count given without format specifier".to_owned())?; + let c = match chars.next() { + Some(c) => c, + None => { + // If we have a repeat count but only whitespace follows, error + if repeat != 1 { + return Err("repeat count given without format specifier".to_owned()); + } + // Otherwise, we're done parsing + break; + } + }; // Check for embedded null character if c == 0 {