Last Comment Bug 439711 - btoa function doesn't encode unicode characters
: btoa function doesn't encode unicode characters
Status: RESOLVED DUPLICATE of bug 213047
:
Product: Core
Classification: Components
Component: DOM (show other bugs)
: unspecified
: All All
: -- major with 1 vote (vote)
: ---
Assigned To: Nobody; OK to take it and work on it
:
: Andrew Overholt [:overholt]
Mentors:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2008-06-17 14:29 PDT by Eli Grey (:sephr)
Modified: 2008-10-17 13:46 PDT (History)
5 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
HTML testcase of btoa bug (2.97 KB, application/xhtml+xml)
2008-06-17 14:37 PDT, Eli Grey (:sephr)
no flags Details
improved testcase (965 bytes, text/html)
2008-09-08 14:03 PDT, Eli Grey (:sephr)
no flags Details

Description User image Eli Grey (:sephr) 2008-06-17 14:29:57 PDT
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9) Gecko/2008052906 Firefox/3.0
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9) Gecko/2008052906 Firefox/3.0

When btoa is passed a string containing unicode such as "→", which is used in the example, it produces the error "String contains an invalid character". It should not do this as it outputs utf-8 base64 strings. It should behave mostly like the non-native implementation I have in the example. This is very important to work when someone is using btoa to base64 encode user-input which can result in lost data.

Reproducible: Always

Steps to Reproduce:
1. Pass btoa some unicode characters.
Actual Results:  
I get the "String contains an invalid character" error.

Expected Results:  
I get the base64 encoded equivalent of the string.
Comment 1 User image Eli Grey (:sephr) 2008-06-17 14:37:27 PDT
Created attachment 325444 [details]
HTML testcase of btoa bug

HTML testcase
Comment 2 User image Brian Crowder 2008-06-17 14:43:47 PDT
This could actually be a bug in NSPR, if it is legit.  Moved to DOM for now, though.
Comment 3 User image karl 2008-07-23 16:01:43 PDT
Easily recreated. I'd like to flag this bug as "important" as btoa is useless for encoding user input. I've had to fall back to using encodeURIComponent instead.
Comment 4 User image Chuck Baker 2008-09-08 13:20:43 PDT
This bug should be either fixed now or the btoa/atob functions be removed from the codebase until it can be fixed.  I am using these functions as part of encryption scheme in an extension I released.  I was unaware of the problem until I started to receive negative feedback. 

A function that works only part of the time is worse than one that doesn't work at all.
Comment 5 User image Eli Grey (:sephr) 2008-09-08 14:03:26 PDT
Created attachment 337525 [details]
improved testcase

Added a new testcase that also gives the error and output of btoa in an alert message and tells if btoa worked.
Comment 6 User image Eli Grey (:sephr) 2008-09-08 14:08:18 PDT
Moved to major for reason of comment #3 and removed url that I didn't really need to have there.
Comment 7 User image Mark Banner (:standard8) 2008-10-17 06:41:25 PDT
This looks like a duplicate of bug 213047
Comment 8 User image Eli Grey (:sephr) 2008-10-17 13:46:21 PDT

*** This bug has been marked as a duplicate of bug 213047 ***

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