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

This commit is contained in:
Tom Alexander 2023-10-08 09:54:10 -04:00
parent bbcafef8bf
commit 120a06055f
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 28 additions and 1 deletions

View File

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

View File

@ -4,11 +4,13 @@ use nom::branch::alt;
use nom::bytes::complete::escaped; use nom::bytes::complete::escaped;
use nom::bytes::complete::is_a; use nom::bytes::complete::is_a;
use nom::bytes::complete::tag; use nom::bytes::complete::tag;
use nom::bytes::complete::take;
use nom::bytes::complete::take_till1; use nom::bytes::complete::take_till1;
use nom::bytes::complete::take_until; use nom::bytes::complete::take_until;
use nom::character::complete::anychar; use nom::character::complete::anychar;
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::opt; use nom::combinator::opt;
@ -16,6 +18,7 @@ use nom::combinator::peek;
use nom::combinator::recognize; use nom::combinator::recognize;
use nom::combinator::rest; use nom::combinator::rest;
use nom::combinator::verify; use nom::combinator::verify;
use nom::multi::many1_count;
use nom::multi::many_till; use nom::multi::many_till;
use nom::sequence::tuple; use nom::sequence::tuple;
use nom::InputTake; use nom::InputTake;
@ -261,7 +264,7 @@ fn file_path_reg<'b, 'g, 'r, 's>(
}); });
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((
alt(( alt((
map( map(
tuple(( tuple((
@ -277,6 +280,10 @@ fn file_path_reg<'b, 'g, 'r, 's>(
map(peek(tag(".")), |_| None), map(peek(tag(".")), |_| None),
map(peek(tag("/")), |_| None), map(peek(tag("/")), |_| None),
)), )),
opt(flat_map(
peek(map(verify(many1_count(tag("/")), |c| *c >= 3), |c| c - 1)),
take,
)),
parser_with_context!(text_until_exit)(&parser_context), parser_with_context!(text_until_exit)(&parser_context),
opt(map( opt(map(
tuple(( tuple((