dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.22k stars 1.57k forks source link

BASE64URL is not compliant with rfc4648 #30854

Open JeromeA opened 7 years ago

JeromeA commented 7 years ago

RFC4648, chapter 5, states in the description of Base64Url that the padding can be skipped.

BASE64URL.decode('AA') raises an exception ("FormatException: Invalid length, must be multiple of four (at character 3)"), when it should return [0], as the padding in 'AA==' is optional.

This could either be fixed in the code (my preference), or in the comments, by saying that contrary to the rfc specifications, this implementation requires padding, and that the user should call the normalize() method before decode() if the padding can be missing.

lrhn commented 7 years ago

Sadly, normalize doesn't work for data URIs (maybe it should, but currently it doesn't).

As I read RFC 4648, padding can be omitted when the data length is known, and I guess that's always the case for data URIs, so it seems like a reasonable feature to have.

JeromeA commented 7 years ago

Why do you mean be "normalize doesn't work"?

BASE64URL.decode(BASE64URL.normalize('AA')) correctly returns [0].

lrhn commented 7 years ago

Ah, my bad, I was confusing it with Uri.normalize.