Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-25513] Windows: Ti.Utils.base64encode behaves different between Android/iOS and Windows

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2018-10-16T12:38:34.000+0000
Affected Version/sRelease 3.2.0
Fix Version/sRelease 7.5.0
ComponentsWindows
Labelsparity
ReporterVarun Joshi
AssigneeKota Iguchi
Created2017-11-15T04:01:20.000+0000
Updated2018-10-16T15:29:30.000+0000

Description

Problem

The result of Ti.Utils.base64encode is different between iOS and Android. On iOS there are newline characters included when the string is long enough, on Android the newline characters are stripped out (which is the correct way to do base64 UTF8 encoding). Please see the attached screenshot explaining the issue.

Sample Code

{noformat} (function() { var win = Ti.UI.createWindow({backgroundColor:'white'}); win.open(); var shortString = 'ABCDEFGHIJ1234567890ABCDEFGHIJ12|psndemo2|abcd:1'; var longString = 'ABCDEFGHIJ1234567890ABCDEFGHIJ12|psndemo2|abcd:12345678901234567890'; var tiBase64ShortResult = Ti.Utils.base64encode(shortString); var tiBase64LongResult = Ti.Utils.base64encode(longString); tiBase64ShortResult = String(tiBase64ShortResult); tiBase64LongResult = String(tiBase64LongResult); // BUG #2: Run this code in iOS and Android and compare the results // On iOS we get newline characters. On Android the newline characters are stripped out. // The correct behavior for UTF8 base64 encoding is to strip out the newline characters. // Android's implementation is correct. tiBase64ShortResult = tiBase64ShortResult.replace(/\r\n/g,"***NEWLINE***"); tiBase64LongResult = tiBase64LongResult.replace(/\r\n/g,"***NEWLINE***"); var alertDialog = Titanium.UI.createAlertDialog( { title: 'Result', message: 'short: ' + tiBase64ShortResult + '\nlong: ' + tiBase64LongResult, buttonNames: ['OK','Cancel'] }); alertDialog.show(); })(); {noformat}

Attachments

FileDateSize
encodedFile.txt2017-11-15T04:01:21.000+000029
Screen shot 2012-05-08 at 3.43.47 PM.png2017-11-15T04:01:21.000+0000690743

Comments

  1. Kota Iguchi 2018-04-12

    https://github.com/appcelerator/titanium_mobile_windows/pull/1220
  2. Keerthi Mahalingam 2018-10-03

    FR Passed. Waiting for CR and merge
  3. Samir Mohammed 2018-10-16

    *Closing ticket*. Verified fix in SDK Version 7.5.0.v20181016071050. Test and other information can be found at: https://github.com/appcelerator/titanium_mobile_windows/pull/1220

JSON Source