tidev / titanium-sdk

🚀 Native iOS and Android Apps with JavaScript
https://titaniumsdk.com/
Other
2.76k stars 1.21k forks source link

iOS: invalid casting on String.format crashes whole app #14092

Open Informate opened 3 months ago

Informate commented 3 months ago

I have searched and made sure there are no existing issues for the issue I am filing

Description

String.format on iOS does not perform a casting conversion and in case you enter a number instead of a string the app crashes inexplicably (for those trying to debug the code). Example:

String.format(“Test %s”,2)

The logs report a segmentation fault:

[ERROR] Application received error: signal error code: 11
[ERROR] (null)
5900 Segmentation fault: 11

Xcode debugger reports:

EXC_BAD_ACCESS (code=1, address=0x3ff00000000000)

Xcode execution stack indicates:

libobjc.A.dylib`objc_opt_respondsToSelector
Foundation`:_NSDescriptionWithStringProxyFunction
CoreFoundation`: __CFStringAppendFormatCore
CoreFoundation`:__CFStringCreateWithFormatAndArgumentsReturningMetadata
TitaniumKit`StringFormatCallback
JavaScriptCore`JSC::callJSCallbackFunction
JavaScriptCore`llint_entry:

FIXING WORKAROUND: Always cast to string function parameters and use %s in the format string:

String.format(“Test %s”,''+2)

Expected Behavior

Correct casting conversion, or at least throw an exception. Do not crashes the app

Actual behavior

Creashes the whole app

Reproducible sample

String.format(“Test %s”,2)

Steps to reproduce

String.format(“Test %s”,2)

Platform

iOS

SDK version you are using

12.4.0

Alloy version you are using

No response