Last Comment Bug 213047 - btoa only works with ISO-8859-1
: btoa only works with ISO-8859-1
Status: RESOLVED INVALID
:
Product: Core
Classification: Components
Component: Internationalization (show other bugs)
: Trunk
: All All
: -- major with 4 votes (vote)
: ---
Assigned To: Simon Montagu :smontagu
:
Mentors:
: 439711 (view as bug list)
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2003-07-18 00:47 PDT by Simon Montagu :smontagu
Modified: 2015-05-30 10:36 PDT (History)
6 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
Test encoding non-ISO-8859-1 strings (965 bytes, text/html)
2008-10-17 13:46 PDT, Eli Grey (:sephr)
no flags Details

Description Simon Montagu :smontagu 2003-07-18 00:47:44 PDT
The btoa() function currently fails with NS_ERROR_DOM_INVALID_CHARACTER_ERR if
the input (in UTF-16) contains characters outside the range of ISO-8859-1, even
if all the characters are single-byte in the encoding of the page.

I think we should be converting the input to the page charset and then
converting to base64, just as we do for escape().
Comment 1 Eli Grey (:sephr) 2008-10-17 13:46:03 PDT
Created attachment 343605 [details]
Test encoding non-ISO-8859-1 strings
Comment 2 Eli Grey (:sephr) 2008-10-17 13:46:21 PDT
*** Bug 439711 has been marked as a duplicate of this bug. ***
Comment 3 Simon Montagu :smontagu 2008-10-18 17:20:04 PDT
-> major per bug 439711 comment 3
Comment 4 Boris Zbarsky [:bz] 2008-10-18 17:33:29 PDT
What does it do in other UAs?  Will changing behavior here break any webpages?
Comment 5 Eli Grey (:sephr) 2008-10-18 17:36:46 PDT
He made it major due to how completely useless btoa is for user input and if it is fixed then extenion developers don't need to make their own Base64 encoding function.
Comment 6 Simon Montagu :smontagu 2008-10-18 17:57:05 PDT
Attachment 343605 [details] fails in Safari also. 

My original suggestion in comment 0 to convert the input to the page encoding is not foolproof, since user input can easily include characters not representable in the page encoding. Maybe a better solution is to explicitly convert the input to UTF-8 before calling btoa?
Comment 7 Boris Zbarsky [:bz] 2008-10-18 18:05:44 PDT
If we're talking about extensions then we don't need to necessarily change the web-facing btoa.  We could provide an XPCOM API for doing this instead.

This bug is about web-facing btoa.  If we need a separate bug for extensions (based on the conclusions reached in this bug), so be it.

My gut feeling is that the suggestion in the last sentence of comment 6 will break sites (any site that is ISO-8859-1 and that does conversion one way on the client and the other on the server, for example!), but I eagerly await a decent analysis of IE's behavior (ideally IE7/quirks, IE7/standards, IE8/standards, in case they differ) here.  That will give us a good starting point for what web sites expect.
Comment 8 Simon Montagu :smontagu 2008-10-18 18:10:47 PDT
(In reply to comment #7)

> My gut feeling is that the suggestion in the last sentence of comment 6 will
> break sites

Then you misunderstood it: I meant that even if we didn't change any code, the extension developer could do the conversion before calling btoa.
Comment 9 :Ms2ger 2011-01-04 11:54:54 PST
Wontfix?
Comment 10 Mike Kaply [:mkaply] 2015-05-28 08:45:03 PDT
I'm really confused about this. The API is called "btoa". binary to ascii.

So by definition, shouldn't it be able to take any binary data? Why is certain data not allowed?

In particular, I don't understand why this doesn't work:

btoa("Firefox Hello — Join the conversation");

Yet if I go to any base 64 encoder, it properly encodes to:

RmlyZWZveCBIZWxsbyDigJQgSm9pbiB0aGUgY29udmVyc2F0aW9u

What am I missing?
Comment 11 :Ms2ger 2015-05-28 09:43:16 PDT
https://html.spec.whatwg.org/multipage/#dom-windowbase64-btoa

Changes to this API can be discussed in all the usual venues for that spec, which does not include this bugzilla instance.

Note You need to log in before you can comment on or make changes to this bug.