mirror of
https://github.com/crate-ci/typos.git
synced 2024-12-22 23:52:12 -05:00
fix(parser): Detect shorter base64 values
This is part of the way to #413. In that case, they aren't providing padding though.
This commit is contained in:
parent
2c5f2ecedd
commit
a39074fc7f
1 changed files with 18 additions and 2 deletions
|
@ -356,7 +356,11 @@ mod parser {
|
||||||
<T as nom::InputIter>::Item: AsChar + Copy,
|
<T as nom::InputIter>::Item: AsChar + Copy,
|
||||||
{
|
{
|
||||||
let (padding, captured) = take_while1(is_base64_digit)(input.clone())?;
|
let (padding, captured) = take_while1(is_base64_digit)(input.clone())?;
|
||||||
if captured.input_len() < 90 {
|
if captured.input_len() < 90
|
||||||
|
&& captured
|
||||||
|
.iter_elements()
|
||||||
|
.all(|c| !['/', '+'].contains(&c.as_char()))
|
||||||
|
{
|
||||||
return Err(nom::Err::Error(nom::error::Error::new(
|
return Err(nom::Err::Error(nom::error::Error::new(
|
||||||
input,
|
input,
|
||||||
nom::error::ErrorKind::LengthValue,
|
nom::error::ErrorKind::LengthValue,
|
||||||
|
@ -1049,7 +1053,7 @@ mod test {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn tokenize_ignore_base64() {
|
fn tokenize_ignore_base64_case_1() {
|
||||||
let parser = TokenizerBuilder::new().build();
|
let parser = TokenizerBuilder::new().build();
|
||||||
|
|
||||||
let input = "Good Iy9+btvut+d92V+v84444ziIqJKHK879KJH59//X1Iy9+btvut+d92V+v84444ziIqJKHK879KJH59//X122Iy9+btvut+d92V+v84444ziIqJKHK879KJH59//X12== Bye";
|
let input = "Good Iy9+btvut+d92V+v84444ziIqJKHK879KJH59//X1Iy9+btvut+d92V+v84444ziIqJKHK879KJH59//X122Iy9+btvut+d92V+v84444ziIqJKHK879KJH59//X12== Bye";
|
||||||
|
@ -1063,6 +1067,18 @@ mod test {
|
||||||
assert_eq!(expected, actual);
|
assert_eq!(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn tokenize_ignore_base64_case_2() {
|
||||||
|
let parser = TokenizerBuilder::new().build();
|
||||||
|
|
||||||
|
let input = r#""ed25519:1": "Wm+VzmOUOz08Ds+0NTWb1d4CZrVsJSikkeRxh6aCcUwu6pNC78FunoD7KNWzqFn241eYHYMGCA5McEiVPdhzBA==""#;
|
||||||
|
let expected: Vec<Identifier> = vec![Identifier::new_unchecked("ed25519", Case::None, 1)];
|
||||||
|
let actual: Vec<_> = parser.parse_bytes(input.as_bytes()).collect();
|
||||||
|
assert_eq!(expected, actual);
|
||||||
|
let actual: Vec<_> = parser.parse_str(input).collect();
|
||||||
|
assert_eq!(expected, actual);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn tokenize_ignore_email() {
|
fn tokenize_ignore_email() {
|
||||||
let parser = TokenizerBuilder::new().build();
|
let parser = TokenizerBuilder::new().build();
|
||||||
|
|
Loading…
Reference in a new issue