Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-11660] iOS: String.format crash with no feedback if the arguments are not strings

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionCannot Reproduce
Resolution Date2013-04-08T11:39:45.000+0000
Affected Version/sRelease 2.1.3, Release 3.0.0
Fix Version/s2013 Sprint 07
ComponentsiOS
Labelsn/a
ReporterFederico Casali
AssigneeShameer Jan
Created2012-10-25T18:10:01.000+0000
Updated2015-06-11T15:08:17.000+0000

Description

Problem description

String.format is crashing the app if the arguments are not strings

Steps to reproduce and sample code

var win = Ti.UI.createWindow({
	title:'test',
	backgroundColor:'white',
});

var cost = 10;
var coins = 20;
var message = String.format(L("menu_iconsbuy"),cost,coins);

// setting cost and coins as Strings, it works
// var message = String.format(L("menu_iconsbuy"),cost.toString(),coins.toString());

Ti.API.info('#### ' + message);

win.open();
strings.xml (in the i18n folder) is:
<?xml version="1.0" encoding="UTF-8"?>
<!-- All localized strings should go here -->
<resources>
	<string name="menu_iconsbuy">This icon set will cost %1$s coins.\n You have %2$s coins\nWant to buy it ?</string>
</resources>
The workaround is to convert the numeric values to string: var message = String.format(L("menu_iconsbuy"),cost.toString(),coins.toString()); Attached the crash log.

Attachments

FileDateSize
11660_log.txt2012-11-02T21:33:58.000+0000486

Comments

  1. Shameer Jan 2013-04-08

    Issue does not 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. Paras Mishra 2013-04-10

    Issue is not reproducible, Hence closing. Verified on: Device : iPad 4, iOS version: 6 SDK: 3.1.0.v20130409124549 CLI version : 3.1.0-cr OS : MAC OSX 10.7.5 Appcelerator Studio, build: 3.1.0.201304052347 XCode : 4.5.1
  3. Manuel Lehner 2015-06-11

    Thanks. It just took me 2 hours to find that bug! value.toString() solved it.

JSON Source