Skip to content

Commit

Permalink
some more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
farooqkz committed Feb 11, 2024
1 parent ed94a50 commit 87993c2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
22 changes: 11 additions & 11 deletions src/parser/parse_from_text/link_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ fn is_other_unreserved(c: char) -> bool {
matches!(c, '_' | '.' | '_' | '~')
}

fn is_pct_encoded(c: [char; 3]) -> bool {
c[0] == '%' && is_hex_digit(c[1]) && is_hex_digit(c[2])
}

fn is_sub_delim(c: char) -> bool {
matches!(
c,
Expand Down Expand Up @@ -198,7 +194,7 @@ fn is_userinfo(c: char) -> bool {
}

fn iauthority(input: &str) -> IResult<&str, (&str, &str, &str, bool)> {
let (input, userinfo) = opt(tuple((take_while(is_userinfo), char('@'))))(input)?;
let (input, userinfo) = opt(recognize(tuple((take_while(is_userinfo), char('@')))))(input)?;
let (input, (host, is_ipv6_or_future)) = parse_host(input)?;
let (input, port) = preceded(char(':'), take_while(is_digit))(input)?;
let userinfo = userinfo.unwrap_or("");
Expand All @@ -225,8 +221,8 @@ fn ihier_part(input: &str) -> IResult<&str, (&str, &str, &str, &str, bool)> {
Ok((input, (userinfo, host, port, path, is_ipv6_or_future)))
}

fn is_ipchar(c: char) -> bool {
is_iunreserved(c) || is_pct_encoded(c) || is_sub_delim(c) || matches!(c, ':' | '@')
fn is_ipchar_not_pct_encoded(c: char) -> bool {
is_iunreserved(c) || is_sub_delim(c) || matches!(c, ':' | '@')
}

const IPRIVATE_RANGES: [RangeInclusive<u32>; 3] =
Expand All @@ -236,12 +232,12 @@ fn is_iprivate(c: char) -> bool {
is_in_one_of_ranges(c, &IPRIVATE_RANGES[..])
}

fn is_iquery(c: char) -> bool {
is_iprivate(c) || is_ipchar(c) || matches!(c, '/' | '?')
fn is_iquery_not_pct_encoded(c: char) -> bool {
is_iprivate(c) || is_ipchar_not_pct_encoded(c) || matches!(c, '/' | '?')
}

fn iquery(input: &str) -> IResult<&str, &str> {
take_while(is_iquery)(input)
recognize(many0(alt((take_while(is_iquery_not_pct_encoded), pct_encoded))))(input)
}

fn is_ifragment(c: char) -> bool {
Expand All @@ -263,10 +259,14 @@ fn is_alphanum_or_hyphen_minus(char: char) -> bool {
}
}

fn pct_encoded(input: &str) -> IResult<&str, &str> {
recognize(tuple((char('%'), take_while_m_n(2, 2, is_hex_digit))))(input)
}

pub fn link(input: &str) -> IResult<&str, Element> {
let (input, scheme) = scheme(input)?;
let (input, (userinfo, host, port, path, is_ipv6_or_future)) = ihier_part(input)?;
let (input, Some(query)) = opt(preceded(char('?'), take_while(is_iquery)))(input)?;
let (input, Some(query)) = opt(preceded(char('?'), iquery))(input)?;
let (input, Some(fragment)) = opt(preceded(char('#'), take_while(is_ifragment)))(input)?;
let mut s = format!("{scheme}://{userinfo}@{host}:{port}{path}?{query}#{fragment}");
Ok((
Expand Down
7 changes: 6 additions & 1 deletion src/parser/parse_from_text/markdown_elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@ pub(crate) fn delimited_link(input: &str) -> IResult<&str, Element, CustomError<
if content.is_empty() {
return Err(nom::Err::Error(CustomError::NoContent));
}
let (rest, link) = link(content)?;
let (rest, link) = match link(content) {
Ok((rest, link)) => (rest, link),
Err(nom::Err(err)) => {

Check failure on line 103 in src/parser/parse_from_text/markdown_elements.rs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-latest, 1.64.0)

expected tuple struct or tuple variant, found enum `nom::Err`

Check failure on line 103 in src/parser/parse_from_text/markdown_elements.rs

View workflow job for this annotation

GitHub Actions / clippy

expected tuple struct or tuple variant, found enum `nom::Err`

error[E0532]: expected tuple struct or tuple variant, found enum `nom::Err` --> src/parser/parse_from_text/markdown_elements.rs:103:13 | 103 | Err(nom::Err(err)) => { | ^^^^^^^^ | help: try to match against one of the enum's variants | 103 | Err(nom::Err::Error(err)) => { | ~~~~~~~~~~~~~~~ 103 | Err(nom::Err::Failure(err)) => { | ~~~~~~~~~~~~~~~~~ 103 | Err(nom::Err::Incomplete(err)) => { | ~~~~~~~~~~~~~~~~~~~~ help: consider importing one of these items instead | 1 | use core::result::Result::Err; | 1 | use nom::lib::std::result::Result::Err; | 1 | use serde::__private::Err; | 1 | use std::result::Result::Err; | help: if you import `Err`, refer to it directly | 103 - Err(nom::Err(err)) => { 103 + Err(Err(err)) => { |
return Err(Error(CustomError::Nom(err.input, err.code)));

Check failure on line 104 in src/parser/parse_from_text/markdown_elements.rs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-latest, 1.64.0)

cannot find function, tuple struct or tuple variant `Error` in this scope

Check failure on line 104 in src/parser/parse_from_text/markdown_elements.rs

View workflow job for this annotation

GitHub Actions / clippy

cannot find function, tuple struct or tuple variant `Error` in this scope

error[E0425]: cannot find function, tuple struct or tuple variant `Error` in this scope --> src/parser/parse_from_text/markdown_elements.rs:104:24 | 104 | return Err(Error(CustomError::Nom(err.input, err.code))); | ^^^^^ not found in this scope | help: consider importing one of these items | 1 | use core::fmt::Error; | 1 | use nom::CompareResult::Error; | 1 | use nom::Err::Error; | 1 | use nom::lib::std::fmt::Error; | and 3 other candidates
}
}

Check failure on line 106 in src/parser/parse_from_text/markdown_elements.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

expected `;`, found keyword `if`

Check failure on line 106 in src/parser/parse_from_text/markdown_elements.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

expected `;`, found keyword `if`

Check failure on line 106 in src/parser/parse_from_text/markdown_elements.rs

View workflow job for this annotation

GitHub Actions / Rust doc comments

expected `;`, found keyword `if`

Check failure on line 106 in src/parser/parse_from_text/markdown_elements.rs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-latest, 1.64.0)

expected `;`, found keyword `if`
if !rest.is_empty() {
return Err(nom::Err::Error(CustomError::UnexpectedContent));
}
Expand Down

0 comments on commit 87993c2

Please sign in to comment.