Skip to content

Commit

Permalink
fix(ascii): Accept 0 with dec_uint/dec_int
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Feb 14, 2024
1 parent 67ed881 commit c9f000a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/ascii/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ where
O: Uint,
{
trace("dec_uint", move |input: &mut I| {
(one_of('1'..='9'), digit0)
alt(((one_of('1'..='9'), digit0).void(), one_of('0').void()))
.recognize()
.verify_map(|s: <I as Stream>::Slice| {
let s = s.as_bstr();
Expand Down Expand Up @@ -994,7 +994,7 @@ where
'-' => empty.value(false),
_ => fail,
});
(sign, one_of('1'..='9'), digit0)
alt(((sign, one_of('1'..='9'), digit0).void(), one_of('0').void()))
.recognize()
.verify_map(|s: <I as Stream>::Slice| {
let s = s.as_bstr();
Expand Down
12 changes: 9 additions & 3 deletions src/ascii/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ mod complete {
ErrorKind::Verify
)))
);
//assert_parse!(dec_u32(&b"0;"[..]), Ok((&b";"[..], 0)));
assert_parse!(dec_u32(&b"0;"[..]), Ok((&b";"[..], 0)));
assert_parse!(dec_u32(&b"1;"[..]), Ok((&b";"[..], 1)));
assert_parse!(dec_u32(&b"32;"[..]), Ok((&b";"[..], 32)));
assert_parse!(
Expand All @@ -464,10 +464,16 @@ mod complete {
ErrorKind::Verify
)))
);
//assert_parse!(dec_i32(&b"0;"[..]), Ok((&b";"[..], 0)));
assert_parse!(dec_i32(&b"0;"[..]), Ok((&b";"[..], 0)));
assert_parse!(dec_i32(&b"1;"[..]), Ok((&b";"[..], 1)));
assert_parse!(dec_i32(&b"32;"[..]), Ok((&b";"[..], 32)));
//assert_parse!(dec_i32(&b"-0;"[..]), Ok((&b";"[..], 0)));
assert_parse!(
dec_i32(&b"-0;"[..]),
Err(ErrMode::Backtrack(error_position!(
&&b"-0;"[..],
ErrorKind::Verify
)))
);
assert_parse!(dec_i32(&b"-1;"[..]), Ok((&b";"[..], -1)));
assert_parse!(dec_i32(&b"-32;"[..]), Ok((&b";"[..], -32)));
assert_parse!(
Expand Down

0 comments on commit c9f000a

Please sign in to comment.