Unverified Commit 38b1261f authored by Kefu Chai's avatar Kefu Chai Committed by GitHub
Browse files

build(deps): upgrade nom from 7.1.3 to 8.0.0 (#237) (#391)



This upgrades the nom parser combinator library to version 8.0.0,
which was released on January 26, 2025. The upgrade was previously
blocked by upstream issue rust-bakery/nom#1799 regarding type
coercion for the Input trait, which has been resolved in the 8.0.0
release.

Changes required for nom 8.0 compatibility:
- Convert array literal tags from `tag(b"...")` to `tag(&b"..."[..])`
  to properly convert array references to slices
- Add `use nom::Parser;` imports where the Parser trait is needed
- Update parser invocations to use `.parse(input)` method or wrap
  in closures when passing to helper functions
- Replace deprecated `tuple()` combinator with direct tuple syntax

Fixes #237

Signed-off-by: default avatarKefu Chai <tchaikov@gmail.com>
Co-authored-by: default avatarNugine <nugine@foxmail.com>
parent ba189bad
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -737,7 +737,7 @@ version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
dependencies = [
 "nom",
 "nom 7.1.3",
]

[[package]]
@@ -2030,6 +2030,15 @@ dependencies = [
 "minimal-lexical",
]

[[package]]
name = "nom"
version = "8.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df9761775871bdef83bee530e60050f7e54b1105350d6884eb0fb4f46c2f9405"
dependencies = [
 "memchr",
]

[[package]]
name = "nu-ansi-term"
version = "0.50.1"
@@ -2776,7 +2785,7 @@ dependencies = [
 "md-5 0.11.0-rc.3",
 "memchr",
 "mime",
 "nom",
 "nom 8.0.0",
 "numeric_cast",
 "openssl",
 "pin-project-lite",
+1 −1
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ itoa = "1.0.15"
md-5.workspace = true
memchr = "2.7.6"
mime = "0.3.17"
nom = "7.1.3"
nom = "8.0.0"
numeric_cast = "0.3.0"
pin-project-lite = "0.2.16"
quick-xml = { version = "0.37.5", features = ["serialize"] }
+6 −4
Original line number Diff line number Diff line
@@ -89,6 +89,7 @@ struct ChunkMeta<'a> {
/// nom parser
fn parse_chunk_meta(mut input: &[u8]) -> nom::IResult<&[u8], ChunkMeta<'_>> {
    use crate::utils::parser::consume;
    use nom::Parser;
    use nom::bytes::complete::{tag, take, take_till1};
    use nom::combinator::{all_consuming, map_res};
    use nom::number::complete::hex_u32;
@@ -98,15 +99,16 @@ fn parse_chunk_meta(mut input: &[u8]) -> nom::IResult<&[u8], ChunkMeta<'_>> {

    // read size until ';' or CR
    let size = consume(s, take_till1(|c| c == b';' || c == b'\r'))?;
    let (_, size) = map_res(hex_u32, TryInto::try_into)(size)?;
    let (_, size) = map_res(hex_u32, TryInto::try_into).parse(size)?;

    // Either ";chunk-signature=<64>\r\n" or just "\r\n"
    let signature = if let Ok(sig) = consume(s, all_consuming(delimited(tag(b";chunk-signature="), take(64_usize), tag(b"\r\n"))))
    {
    let signature = if let Ok(sig) = consume(s, |i| {
        all_consuming(delimited(tag(&b";chunk-signature="[..]), take(64_usize), tag(&b"\r\n"[..]))).parse(i)
    }) {
        Some(sig)
    } else {
        // If no signature extension, accept plain CRLF
        let _ = consume(s, all_consuming(tag(b"\r\n")))?;
        let _ = consume(s, |i| all_consuming(tag(&b"\r\n"[..])).parse(i))?;
        None
    };

+13 −8
Original line number Diff line number Diff line
@@ -431,26 +431,31 @@ struct ContentDisposition<'a> {

/// parse content disposition value
fn parse_content_disposition(input: &[u8]) -> nom::IResult<&[u8], ContentDisposition<'_>> {
    use nom::Parser;
    use nom::bytes::complete::{tag, take, take_till1};
    use nom::combinator::{all_consuming, map_res, opt};
    use nom::sequence::{delimited, preceded, tuple};
    use nom::sequence::{delimited, preceded};

    // TODO: escape?

    let parse_name = delimited(tag(b"name=\""), map_res(take_till1(|c| c == b'"'), std::str::from_utf8), take(1_usize));
    let parse_name = delimited(
        tag(&b"name=\""[..]),
        map_res(take_till1(|c| c == b'"'), std::str::from_utf8),
        take(1_usize),
    );

    let parse_filename = delimited(
        tag(b"filename=\""),
        tag(&b"filename=\""[..]),
        map_res(take_till1(|c| c == b'"'), std::str::from_utf8),
        take(1_usize),
    );

    let mut parse = all_consuming(tuple((
        preceded(tag(b"form-data; "), parse_name),
        opt(preceded(tag(b"; "), parse_filename)),
    )));
    let mut parse = all_consuming((
        preceded(tag(&b"form-data; "[..]), parse_name),
        opt(preceded(tag(&b"; "[..]), parse_filename)),
    ));

    let (remaining, (name, filename)) = parse(input)?;
    let (remaining, (name, filename)) = parse.parse(input)?;

    Ok((remaining, ContentDisposition { name, filename }))
}
+7 −6
Original line number Diff line number Diff line
@@ -82,6 +82,7 @@ mod parser {
    use crate::utils::parser::{Error, consume, digit2, digit4};

    use nom::IResult;
    use nom::Parser;
    use nom::bytes::complete::{tag, take, take_till, take_till1};
    use nom::character::complete::{multispace0, multispace1};
    use nom::combinator::verify;
@@ -94,14 +95,14 @@ mod parser {
        let algorithm = consume(s, till_space1)?;

        consume(s, multispace1)?;
        let credential = consume(s, delimited(tag("Credential="), parse_credential, tag(",")))?;
        let credential = consume(s, |i| delimited(tag("Credential="), parse_credential, tag(",")).parse(i))?;

        consume(s, multispace0)?;
        let parse_headers = separated_list1(tag(";"), take_till(|c| c == ';' || c == ','));
        let signed_headers = consume(s, delimited(tag("SignedHeaders="), parse_headers, tag(",")))?;
        let signed_headers = consume(s, |i| delimited(tag("SignedHeaders="), parse_headers, tag(",")).parse(i))?;

        consume(s, multispace0)?;
        let signature = consume(s, preceded(tag("Signature="), till_space0))?;
        let signature = consume(s, |i| preceded(tag("Signature="), till_space0).parse(i))?;

        consume(s, multispace0)?;

@@ -127,7 +128,7 @@ mod parser {
        let s = &mut input;

        let access_key_id = consume(s, until_slash0)?;
        let date = consume(s, verify(until_slash1, |s| verify_date(s).is_ok()))?;
        let date = consume(s, |i| verify(until_slash1, |s| verify_date(s).is_ok()).parse(i))?;
        let aws_region = consume(s, until_slash0)?;
        let aws_service = consume(s, until_slash1)?;
        consume(s, tag("aws4_request"))?;
@@ -143,11 +144,11 @@ mod parser {
    }

    fn until_slash0(input: &str) -> IResult<&str, &str> {
        terminated(take_till(|c| c == '/'), take(1_usize))(input)
        terminated(take_till(|c| c == '/'), take(1_usize)).parse(input)
    }

    fn until_slash1(input: &str) -> IResult<&str, &str> {
        terminated(take_till1(|c| c == '/'), take(1_usize))(input)
        terminated(take_till1(|c| c == '/'), take(1_usize)).parse(input)
    }

    fn verify_date(s: &str) -> Result<(), Error> {