[TIMOB-9110] iOS: javascript function replace not working on the result of Ti.Utils.base64encode
GitHub Issue | n/a |
Type | Bug |
Priority | Medium |
Status | Closed |
Resolution | Invalid |
Resolution Date | 2014-12-18T21:44:49.000+0000 |
Affected Version/s | Release 2.0.1, Release 3.1.0, Release 3.2.0 |
Fix Version/s | n/a |
Components | iOS |
Labels | SupportTeam, core |
Reporter | Varun Joshi |
Assignee | Ingo Muschenetz |
Created | 2012-05-11T12:17:57.000+0000 |
Updated | 2017-03-20T21:56:39.000+0000 |
Description
Problem
The replace javascript function does not work on a large base64 encoded string. Please run the code below to reproduce the issue. Also attached is the screenshot of the error.
{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);
// BUG: without the two lines below get an error when trying to use "replace" on the base64 string
//tiBase64ShortResult = String(tiBase64ShortResult);
//tiBase64LongResult = String(tiBase64LongResult);
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}
The issue is resolved on casting the output of base64 encode to a String. Is this an expected result?
Attachments
Issue reproduces Tested with Titanium Studio, build: 3.0.1.201212181159 Titanium SDK version: 3.1.0 Titanium SDK version: 3.0.2 iOS iPhone Simulator: iOS SDK version: 6.0
This is not actually a bug. Docs say that Ti.Utils.base64encode() returns a Ti.Blob. Use Ti.Blob.toString() to convert to a String and all the String methods.
Not a bug. Marking as such.
Closing ticket as invalid.