mirror of
https://github.com/crate-ci/typos.git
synced 2025-01-11 01:01:36 -05:00
fix(parser): Recognize URLs with passwords
This commit is contained in:
parent
05773fe815
commit
09203fd592
1 changed files with 24 additions and 3 deletions
|
@ -422,7 +422,7 @@ mod parser {
|
||||||
tuple((char(':'), char('/'), char('/'))),
|
tuple((char(':'), char('/'), char('/'))),
|
||||||
)),
|
)),
|
||||||
tuple((
|
tuple((
|
||||||
opt(terminated(take_while1(is_localport_char), char('@'))),
|
opt(terminated(url_userinfo, char('@'))),
|
||||||
take_while1(is_domain_char),
|
take_while1(is_domain_char),
|
||||||
opt(preceded(char(':'), take_while1(AsChar::is_dec_digit))),
|
opt(preceded(char(':'), take_while1(AsChar::is_dec_digit))),
|
||||||
)),
|
)),
|
||||||
|
@ -432,6 +432,26 @@ mod parser {
|
||||||
)))(input)
|
)))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn url_userinfo<T>(input: T) -> IResult<T, T>
|
||||||
|
where
|
||||||
|
T: nom::InputTakeAtPosition
|
||||||
|
+ nom::InputTake
|
||||||
|
+ nom::InputIter
|
||||||
|
+ nom::InputLength
|
||||||
|
+ nom::Offset
|
||||||
|
+ nom::Slice<std::ops::RangeTo<usize>>
|
||||||
|
+ nom::Slice<std::ops::RangeFrom<usize>>
|
||||||
|
+ Clone
|
||||||
|
+ std::fmt::Debug,
|
||||||
|
<T as nom::InputTakeAtPosition>::Item: AsChar + Copy,
|
||||||
|
<T as nom::InputIter>::Item: AsChar + Copy,
|
||||||
|
{
|
||||||
|
recognize(tuple((
|
||||||
|
take_while1(is_localport_char),
|
||||||
|
opt(preceded(char(':'), take_while(is_localport_char))),
|
||||||
|
)))(input)
|
||||||
|
}
|
||||||
|
|
||||||
fn c_escape<T>(input: T) -> IResult<T, T>
|
fn c_escape<T>(input: T) -> IResult<T, T>
|
||||||
where
|
where
|
||||||
T: nom::InputTakeAtPosition
|
T: nom::InputTakeAtPosition
|
||||||
|
@ -1113,10 +1133,11 @@ mod test {
|
||||||
fn tokenize_ignore_max_url() {
|
fn tokenize_ignore_max_url() {
|
||||||
let parser = TokenizerBuilder::new().build();
|
let parser = TokenizerBuilder::new().build();
|
||||||
|
|
||||||
let input = "Good http://user@example.com:3142/hello?query=value&extra=two#fragment Bye";
|
let input =
|
||||||
|
"Good http://user:password@example.com:3142/hello?query=value&extra=two#fragment Bye";
|
||||||
let expected: Vec<Identifier> = vec![
|
let expected: Vec<Identifier> = vec![
|
||||||
Identifier::new_unchecked("Good", Case::None, 0),
|
Identifier::new_unchecked("Good", Case::None, 0),
|
||||||
Identifier::new_unchecked("Bye", Case::None, 71),
|
Identifier::new_unchecked("Bye", Case::None, 80),
|
||||||
];
|
];
|
||||||
let actual: Vec<_> = parser.parse_bytes(input.as_bytes()).collect();
|
let actual: Vec<_> = parser.parse_bytes(input.as_bytes()).collect();
|
||||||
assert_eq!(expected, actual);
|
assert_eq!(expected, actual);
|
||||||
|
|
Loading…
Reference in a new issue