From 63def4e16b1273f702f1a77f19a0b61d2bcb1e18 Mon Sep 17 00:00:00 2001 From: boxdot Date: Sat, 21 Oct 2023 15:10:57 +0200 Subject: [PATCH] fix: parse "infinity" literal fully in `float` (#1673) `float` first parsed the "inf" literal and then "infinity", therefore even though the latter was parsed correctly, the suffix "inity" was returned as remaining input, which is not correct. Co-authored-by: Geoffroy Couprie --- src/number/complete.rs | 7 ++++--- src/number/mod.rs | 9 +++++---- src/number/streaming.rs | 7 ++++--- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/number/complete.rs b/src/number/complete.rs index b4a451495..d8a2a978e 100644 --- a/src/number/complete.rs +++ b/src/number/complete.rs @@ -1283,11 +1283,11 @@ where .map_err(|_| crate::Err::Error(E::from_error_kind(i, ErrorKind::Float))) }, |i: T| { - crate::bytes::complete::tag_no_case::<_, _, E>("inf")(i.clone()) + crate::bytes::complete::tag_no_case::<_, _, E>("infinity")(i.clone()) .map_err(|_| crate::Err::Error(E::from_error_kind(i, ErrorKind::Float))) }, |i: T| { - crate::bytes::complete::tag_no_case::<_, _, E>("infinity")(i.clone()) + crate::bytes::complete::tag_no_case::<_, _, E>("inf")(i.clone()) .map_err(|_| crate::Err::Error(E::from_error_kind(i, ErrorKind::Float))) }, )) @@ -1853,8 +1853,9 @@ mod tests { let (_i, inf) = float::<_, ()>("inf").unwrap(); assert!(inf.is_infinite()); - let (_i, inf) = float::<_, ()>("infinite").unwrap(); + let (i, inf) = float::<_, ()>("infinity").unwrap(); assert!(inf.is_infinite()); + assert!(i.is_empty()); } #[test] diff --git a/src/number/mod.rs b/src/number/mod.rs index 217aa75d9..1dda79c16 100644 --- a/src/number/mod.rs +++ b/src/number/mod.rs @@ -1328,11 +1328,11 @@ where .map_err(|_| crate::Err::Error(E::from_error_kind(i, ErrorKind::Float))) }, |i: T| { - crate::bytes::streaming::tag_no_case::<_, _, E>("inf")(i.clone()) + crate::bytes::streaming::tag_no_case::<_, _, E>("infinity")(i.clone()) .map_err(|_| crate::Err::Error(E::from_error_kind(i, ErrorKind::Float))) }, |i: T| { - crate::bytes::streaming::tag_no_case::<_, _, E>("infinity")(i.clone()) + crate::bytes::streaming::tag_no_case::<_, _, E>("inf")(i.clone()) .map_err(|_| crate::Err::Error(E::from_error_kind(i, ErrorKind::Float))) }, )) @@ -1449,7 +1449,8 @@ mod tests { let (_i, inf) = float::<_, ()>("inf").unwrap(); assert!(inf.is_infinite()); - let (_i, inf) = float::<_, ()>("infinite").unwrap(); - assert!(inf.is_infinite());*/ + let (i, inf) = float::<_, ()>("infinity").unwrap(); + assert!(inf.is_infinite()); + assert!(i.is_empty());*/ } } diff --git a/src/number/streaming.rs b/src/number/streaming.rs index 9262f4e08..2da0335fd 100644 --- a/src/number/streaming.rs +++ b/src/number/streaming.rs @@ -1250,11 +1250,11 @@ where .map_err(|_| crate::Err::Error(E::from_error_kind(i, ErrorKind::Float))) }, |i: T| { - crate::bytes::streaming::tag_no_case::<_, _, E>("inf")(i.clone()) + crate::bytes::streaming::tag_no_case::<_, _, E>("infinity")(i.clone()) .map_err(|_| crate::Err::Error(E::from_error_kind(i, ErrorKind::Float))) }, |i: T| { - crate::bytes::streaming::tag_no_case::<_, _, E>("infinity")(i.clone()) + crate::bytes::streaming::tag_no_case::<_, _, E>("inf")(i.clone()) .map_err(|_| crate::Err::Error(E::from_error_kind(i, ErrorKind::Float))) }, )) @@ -1928,8 +1928,9 @@ mod tests { let (_i, inf) = float::<_, ()>("inf").unwrap(); assert!(inf.is_infinite()); - let (_i, inf) = float::<_, ()>("infinite").unwrap(); + let (i, inf) = float::<_, ()>("infinity").unwrap(); assert!(inf.is_infinite()); + assert!(i.is_empty()); } #[test]