Skip to content

Commit 99cde84

Browse files
committed
Ignore all newline characters in Base64 decoder
Ignore all newline characters in Base64 decoder to make it compatible with other Base64 decoders.
1 parent bf07c80 commit 99cde84

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/libextra/base64.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,9 @@ impl<'a> FromBase64 for &'a str {
237237
}
238238

239239
for (idx, byte) in it {
240-
if (byte as char) != '=' {
241-
return Err(InvalidBase64Character(self.char_at(idx), idx));
240+
match byte as char {
241+
'='|'\r'|'\n' => continue,
242+
_ => return Err(InvalidBase64Character(self.char_at(idx), idx)),
242243
}
243244
}
244245

@@ -310,6 +311,8 @@ mod test {
310311
fn test_from_base64_newlines() {
311312
assert_eq!("Zm9v\r\nYmFy".from_base64().unwrap(),
312313
"foobar".as_bytes().to_owned());
314+
assert_eq!("Zm9vYg==\r\n".from_base64().unwrap(),
315+
"foob".as_bytes().to_owned());
313316
}
314317

315318
#[test]

0 commit comments

Comments
 (0)