diff options
| author | Dmitry Vasiliev <dima@hlabs.org> | 2014-01-18 19:18:44 +0100 |
|---|---|---|
| committer | Dmitry Vasiliev <dima@hlabs.org> | 2014-01-18 19:18:44 +0100 |
| commit | 99cde8482efaed4757422d24cd46de8fa64c92cb (patch) | |
| tree | 6fefd13480c4696e567507b5b0b14a6aef70a035 /src/libextra | |
| parent | bf07c80838e59cb21748f7e3b092ced96f41a208 (diff) | |
| download | rust-99cde8482efaed4757422d24cd46de8fa64c92cb.tar.gz rust-99cde8482efaed4757422d24cd46de8fa64c92cb.zip | |
Ignore all newline characters in Base64 decoder
Ignore all newline characters in Base64 decoder to make it compatible with other Base64 decoders.
Diffstat (limited to 'src/libextra')
| -rw-r--r-- | src/libextra/base64.rs | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/libextra/base64.rs b/src/libextra/base64.rs index 6f9475d091a..1043f700aa7 100644 --- a/src/libextra/base64.rs +++ b/src/libextra/base64.rs @@ -237,8 +237,9 @@ impl<'a> FromBase64 for &'a str { } for (idx, byte) in it { - if (byte as char) != '=' { - return Err(InvalidBase64Character(self.char_at(idx), idx)); + match byte as char { + '='|'\r'|'\n' => continue, + _ => return Err(InvalidBase64Character(self.char_at(idx), idx)), } } @@ -310,6 +311,8 @@ mod test { fn test_from_base64_newlines() { assert_eq!("Zm9v\r\nYmFy".from_base64().unwrap(), "foobar".as_bytes().to_owned()); + assert_eq!("Zm9vYg==\r\n".from_base64().unwrap(), + "foob".as_bytes().to_owned()); } #[test] |
