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.09k stars 1.56k forks source link

UriData.fromString sets charset for non-text mime types #37041

Open robertbastian opened 5 years ago

robertbastian commented 5 years ago
UriData.fromString('🍌', mimeType: 'application/octet-stream', encoding: utf8);

produces

data:application/octet-stream;charset=utf-8,%F0%9F%8D%8C

However, the charset is pointless for this mime type (and others), and should not be set without the user explicitly asking for it. The dartdoc does not mention this behaviour: https://github.com/dart-lang/sdk/blob/master/sdk/lib/core/uri.dart#L299

lrhn commented 5 years ago

Well played. Turnabout is fair play. :)

We could only add charset implicitly if the mime-type is text/something. However, some application/* types may also allow a charset property, and we are not going to include a dictionary of which types allow which properties. So, that's not a viable solution

More likely, we'll just document that the fromString will always include a charset header, and if you don't want that, you should use .fromBytes(encoding.encode(string)) instead of .fromString(string, encoding: encoding).