mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-09 22:49:57 +09:00
Fix wrong int type casting with radix and larger base value
Fix base value check logic when string have regex Fixed: #1408
This commit is contained in:
committed by
lntuition
parent
51c3f71eed
commit
d82fee7afa
@@ -123,6 +123,11 @@ with assert_raises(ValueError):
|
||||
with assert_raises(ValueError):
|
||||
int(b"F\xc3\xb8\xc3\xb6\xbbB\xc3\xa5r")
|
||||
|
||||
# string looks like radix
|
||||
assert int('0b1', base=12) == 133
|
||||
assert int('0o1', base=25) == 601
|
||||
assert int('0x1', base=34) == 1123
|
||||
|
||||
# underscore
|
||||
assert int('0xFF_FF_FF', base=16) == 16_777_215
|
||||
with assert_raises(ValueError):
|
||||
|
||||
@@ -792,13 +792,16 @@ fn str_to_int(vm: &VirtualMachine, literal: &str, base: &BigInt) -> PyResult<Big
|
||||
// try to find base
|
||||
if let Some(radix_candidate) = radix_candidate {
|
||||
if let Some(matched_radix) = detect_base(&radix_candidate) {
|
||||
if base_u32 != 0 && base_u32 != matched_radix {
|
||||
return Err(invalid_literal(vm, literal, base));
|
||||
} else {
|
||||
if base_u32 == 0 || base_u32 == matched_radix {
|
||||
base_u32 = matched_radix;
|
||||
}
|
||||
buf.drain(radix_range);
|
||||
|
||||
buf.drain(radix_range);
|
||||
} else if (matched_radix == 2 && base_u32 < 12)
|
||||
|| (matched_radix == 8 && base_u32 < 25)
|
||||
|| (matched_radix == 16 && base_u32 < 34)
|
||||
{
|
||||
return Err(invalid_literal(vm, literal, base));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user