Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-9110] iOS: javascript function replace not working on the result of Ti.Utils.base64encode

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionInvalid
Resolution Date2014-12-18T21:44:49.000+0000
Affected Version/sRelease 2.0.1, Release 3.1.0, Release 3.2.0
Fix Version/sn/a
ComponentsiOS
LabelsSupportTeam, core
ReporterVarun Joshi
AssigneeIngo Muschenetz
Created2012-05-11T12:17:57.000+0000
Updated2017-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

FileDateSize
Screen Shot 2012-05-11 at 3.16.53 PM.png2012-05-11T12:17:57.000+0000115085

Comments

  1. jithinpv 2013-04-12

    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
  2. Shannon Hicks 2014-12-18

    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.
  3. Ingo Muschenetz 2014-12-18

    Not a bug. Marking as such.
  4. Lee Morris 2017-03-20

    Closing ticket as invalid.

JSON Source