Merge pull request #414 from epage/base64

fix(parser): Detect shorter base64 values
This commit is contained in:
Ed Page 2022-01-26 14:30:29 -06:00 committed by GitHub
commit 3affa63856
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -356,7 +356,11 @@ mod parser {
<T as nom::InputIter>::Item: AsChar + Copy,
{
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(
input,
nom::error::ErrorKind::LengthValue,
@ -1049,7 +1053,7 @@ mod test {
}
#[test]
fn tokenize_ignore_base64() {
fn tokenize_ignore_base64_case_1() {
let parser = TokenizerBuilder::new().build();
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);
}
#[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]
fn tokenize_ignore_email() {
let parser = TokenizerBuilder::new().build();