Titanium JIRA Archive
Appcelerator Community (AC)

[AC-845] Strings.format crashes on iOS

GitHub Issuen/a
TypeBug
Priorityn/a
StatusResolved
ResolutionCannot Reproduce
Resolution Date2015-09-30T02:50:39.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labelsios
Reportergrebulon
AssigneeShak Hossain
Created2015-05-06T08:11:23.000+0000
Updated2016-03-08T07:37:08.000+0000

Description

The following statement crashes on iPhone: String.format(" & %1$s more...", "a, b, c", 5); *Notes*

I'm passing an integer as a string argument (%s)

This doesn't raise a runtime error, it crashes out of the app straight to the launcher

This may be a *security problem*. I don't have time to attempt an exploit, but I have a feeling that there is one...

This works perfectly on Android

C-style printf is not appropriate for Javascript. You should replace this with some sort of typeless template replacement.

Replacing 5 with ""+5 results in "more..." being dropped: String.format(" & %1$s more...", "a, b, c", ""+5); results with a, b, c & 5

Attachments

FileDateSize
iOS Simulator Screen Shot May 7, 2015, 6.47.01 PM.png2015-05-07T12:52:44.000+000026668
iOS Simulator Screen Shot May 7, 2015, 6.48.26 PM.png2015-05-07T12:52:44.000+000026685

Comments

  1. Harish Mridha 2015-05-07

    Hi , We have tested this issue and unable to reproduce it. We used the following test case. If you can provide us a test sample that reproduces the issue, we will investigate it further. Please find the screen sort.
       var w = Ti.UI.createWindow({
         backgroundColor: 'white'
       });
        
       w.add(Ti.UI.createLabel({
         //text: String.format(" & %1$s more...", "a, b, c", 5),
          text:String.format(" & %1$s more...", "a, b, c", ""+5),
         
       }));
        
       w.open();
       
    Thanks

JSON Source