Fix str.zfill() width calculation for non-ASCII strings (#7534)

This commit is contained in:
Copilot authored and GitHub committed 2026-04-04 14:45:30 +09:00
1 parent a022ccc39f
commit b682ec3bbe
2 files changed
+7

No files matched your search

+4
View File
@@ -396,6 +396,10 @@ pub trait AnyStr {
fn py_zfill(&self, width: isize) -> Vec<u8> {
let width = width.to_usize().unwrap_or(0);
let char_len = self.elements().count();
let width = self
.bytes_len()
.saturating_add(width.saturating_sub(char_len));
rustpython_common::str::zfill(self.as_bytes(), width)
}
+3
View File
@@ -61,6 +61,9 @@ assert a.endswith(("A", "lo"))
assert not a.endswith("on")
assert not a.endswith(("A", "ll"))
assert a.zfill(8) == "000Hallo"
assert "á".zfill(4) == "000á"
assert "🙂".zfill(5) == "0000🙂"
assert "+あ".zfill(5) == "+000あ"
assert a.isalnum()
assert not a.isdigit()
assert not a.isdecimal()