Skip to content

Ignore all newline characters in Base64 decoder #11652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 20, 2014

Conversation

hdima
Copy link
Contributor

@hdima hdima commented Jan 18, 2014

Ignore all newline characters in Base64 decoder to make it compatible with other Base64 decoders.

Most of the Base64 decoder implementations ignore all newline characters in the input string. There are some examples:

Python:

>>> "\nA\nQ\n=\n=\n".decode("base64")
'\x01'

Ruby:

irb(main):001:0> "\nA\nQ\n=\n=\n".unpack("m")
=> ["\001"]

Erlang:

1> base64:decode("\nA\nQ\n=\n=\n").
<<1>>

Moreover some Base64 encoders append newline character at the end of the output string by default:

Python:

>>> "\1".encode("base64")
'AQ==\n'

Ruby:

irb(main):001:0> ["\1"].pack("m")
=> "AQ==\n"

So I think it's fairly important for Rust Base64 decoder to accept Base64 inputs even with newline characters in the padding.

Ignore all newline characters in Base64 decoder to make it compatible
with other Base64 decoders.
@sfackler
Copy link
Member

The diff seems to only ignore newlines at the end of the string but the PR description seems to say that it should ignore newlines anywhere in the string. Is this intentional?

@hdima
Copy link
Contributor Author

hdima commented Jan 19, 2014

@sfackler Yes, it's intentional. Newlines already ignored in the Base64 body: https://github.com/mozilla/rust/blob/master/src/libextra/base64.rs#L224 But at the end of the string only '=' padding character was expected: https://github.com/mozilla/rust/blob/master/src/libextra/base64.rs#L240

bors added a commit that referenced this pull request Jan 20, 2014
…hton

Ignore all newline characters in Base64 decoder to make it compatible with other Base64 decoders.

Most of the Base64 decoder implementations ignore all newline characters in the input string. There are some examples:

Python:

```python
>>> "
A
Q
=
=
".decode("base64")
'\x01'
```

Ruby:

```ruby
irb(main):001:0> "
A
Q
=
=
".unpack("m")
=> ["�"]
```

Erlang:

```erlang
1> base64:decode("
A
Q
=
=
").
<<1>>
```

Moreover some Base64 encoders append newline character at the end of the output string by default:

Python:

```python
>>> "�".encode("base64")
'AQ==
'
```

Ruby:

```ruby
irb(main):001:0> ["�"].pack("m")
=> "AQ==
"
```

So I think it's fairly important for Rust Base64 decoder to accept Base64 inputs even with newline characters in the padding.
@bors bors closed this Jan 20, 2014
@bors bors merged commit 99cde84 into rust-lang:master Jan 20, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants