Project: titanium
Issue TIMOB-9111: iOS: Ti.Utils.base64encode result is different between iOS and Android
h3. 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. h3. 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}
Story points: 5