Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-15590] Titanium.Utils.base64decode truncates result with foreign characters

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionDuplicate
Resolution Date2017-08-08T22:20:42.000+0000
Affected Version/sRelease 3.1.3
Fix Version/sn/a
ComponentsiOS
LabelsSupportTeam, reprod
ReporterMostafizur Rahman
AssigneeEric Merriman
Created2013-10-26T20:35:52.000+0000
Updated2017-08-15T20:17:16.000+0000

Description

Problem description

Titanium.Utils.base64encode generates a truncated blob when operating on Chinese characters.

Code sample:

var original = '一些随机的中国文字';
var reference = '5LiA5Lqb6ZqP5py655qE5Lit5Zu95paH5a2X';
var encoded = Titanium.Utils.base64encode(original).text;
console.log('encoded: ' + encoded);
console.log('reference: ' + reference);
console.log('encoded ' + (encoded === reference ? '===' : '!==') + ' reference');

Steps to reproduce

1. Create a new mobile project 2. Paste this to app.js: 3. Run and check the console.

Output:

{noformat} encoded: 5LiA5Lqb6ZqP reference: 5LiA5Lqb6ZqP5py655qE5Lit5Zu95paH5a2X encoded !== reference {noformat}

Expected output:

{noformat} encoded: 5LiA5Lqb6ZqP5py655qE5Lit5Zu95paH5a2X reference: 5LiA5Lqb6ZqP5py655qE5Lit5Zu95paH5a2X encoded === reference {noformat} When "original" is Base64-encoded, the result should be equal to "reference". However, the blob returned by Titanium.Utils.base64encode is significantly shorter than expected. Titanium.Utils.base64encode apparently cannot properly handle special characters.

Comments

  1. Ivo 2016-09-01

    We also have the same problem when Chinese characters are present in the string data we want to base64 encode.
  2. Lee Morris 2017-06-21

    I am able to reproduce this issue with the following environment; iPhone 7 (10.2) Studio 4.9.0.201705302345 Ti SDK 6.1.1.v20170620103414 Appc NPM 4.2.9 Appc CLI 6.2.1 Ti CLI 5.0.13 Alloy 1.9.11 Arrow 2.0.0 Xcode 8.2 (8C38) Node v4.8.2 Java 1.8.0_131
  3. Hans Knöchel 2017-08-08

    Marking as duplicate of TIMOB-20395.
  4. Hans Knöchel 2017-08-08

    Fixed as part of TIMOB-20395.
  5. Lee Morris 2017-08-15

    Closing as duplicate.

JSON Source