mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Fix str.zfill() width calculation for non-ASCII strings (#7534)
This commit is contained in:
1 parent
a022ccc39f
commit
b682ec3bbe
2 files changed
+7
No files matched your search
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in new issue
Block a user