Handle 3 or more slashes in the path for plain links.

This commit is contained in:
Tom Alexander 2023-10-08 09:51:12 -04:00
parent 038535174b
commit bbcafef8bf
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 21 additions and 1 deletions

View File

@ -0,0 +1,13 @@
file:foo
file:/bar
file://baz
file:///lorem
file:////ipsum
file://///dolar
https:foo
https:/bar
https://baz
https:///lorem
https:////ipsum
https://///dolar

View File

@ -2,11 +2,13 @@ use nom::branch::alt;
use nom::bytes::complete::is_not; use nom::bytes::complete::is_not;
use nom::bytes::complete::tag; use nom::bytes::complete::tag;
use nom::bytes::complete::tag_no_case; use nom::bytes::complete::tag_no_case;
use nom::bytes::complete::take;
use nom::character::complete::anychar; use nom::character::complete::anychar;
use nom::character::complete::none_of; use nom::character::complete::none_of;
use nom::character::complete::one_of; use nom::character::complete::one_of;
use nom::combinator::consumed; use nom::combinator::consumed;
use nom::combinator::eof; use nom::combinator::eof;
use nom::combinator::flat_map;
use nom::combinator::map; use nom::combinator::map;
use nom::combinator::map_parser; use nom::combinator::map_parser;
use nom::combinator::not; use nom::combinator::not;
@ -17,6 +19,7 @@ use nom::combinator::rest;
use nom::combinator::verify; use nom::combinator::verify;
use nom::multi::many0; use nom::multi::many0;
use nom::multi::many1; use nom::multi::many1;
use nom::multi::many1_count;
use nom::multi::many_till; use nom::multi::many_till;
use nom::sequence::tuple; use nom::sequence::tuple;
@ -135,13 +138,17 @@ fn file_path_plain<'b, 'g, 'r, 's>(
exit_matcher: &path_plain_end, exit_matcher: &path_plain_end,
}); });
let parser_context = context.with_additional_node(&parser_context); let parser_context = context.with_additional_node(&parser_context);
let (remaining, (raw_link, (_, application, _, path, search_option))) = consumed(tuple(( let (remaining, (raw_link, (_, application, _, _, path, search_option))) = consumed(tuple((
peek(tag("file")), peek(tag("file")),
map_parser( map_parser(
parser_with_context!(protocol)(&parser_context), parser_with_context!(protocol)(&parser_context),
parse_file_and_application, parse_file_and_application,
), ),
tag(":"), tag(":"),
opt(flat_map(
peek(map(verify(many1_count(tag("/")), |c| *c >= 3), |c| c - 1)),
take,
)),
parser_with_context!(path_plain)(&parser_context), parser_with_context!(path_plain)(&parser_context),
opt(map( opt(map(
tuple(( tuple((