diegoles / closure-library

Automatically exported from code.google.com/p/closure-library
0 stars 0 forks source link

goog.crypt.base64.decodeString fails on UTF-8 encoded string #527

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago

What steps will reproduce the problem?
1. Use goog.crypt.base64.encodeString on a UTF8 encoded string or 
goog.crypt.base64.decodeString on a Base64-encoded UTF8 string.

What is the expected output? What do you see instead?
The encoding/decoding is not done correctly. It looks like the base64 
encode/decode are not using the utf8 byte array methods (see example below).

What version of the product are you using? On what operating system?

Please provide any additional information below.

Here's an example:

goog.require('goog.crypt.base64');

var utf8string = 'kūhl';

var base64 = goog.crypt.base64.encodeString(utf8string, true);
console.log('base64: ' + base64);
var decoded = goog.crypt.base64.decodeString(base64, true);
console.log('decoded: ' + decoded);

var base64Correct = goog.crypt.base64.encodeByteArray(
          goog.crypt.stringToUtf8ByteArray(utf8string), true);
console.log('base64Correct: ' + base64Correct);
var correct = goog.crypt.utf8ByteArrayToString(
              goog.crypt.base64.decodeStringToByteArray(base64Correct, true));
console.log('correct: ' + correct);

Note: we cannot accept patches without the contributor license agreement
being signed. See http://code.google.com/p/closure-
library/wiki/Contributors for more info.

Original issue reported on code.google.com by t...@vline.me on 10 Jan 2013 at 10:37