[TIMOB-25513] Windows: Ti.Utils.base64encode behaves different between Android/iOS and Windows
GitHub Issue | n/a |
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2018-10-16T12:38:34.000+0000 |
Affected Version/s | Release 3.2.0 |
Fix Version/s | Release 7.5.0 |
Components | Windows |
Labels | parity |
Reporter | Varun Joshi |
Assignee | Kota Iguchi |
Created | 2017-11-15T04:01:20.000+0000 |
Updated | 2018-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
https://github.com/appcelerator/titanium_mobile_windows/pull/1220
FR Passed. Waiting for CR and merge
*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