EddyVerbruggen / cordova-plugin-actionsheet

:clipboard: ActionSheet plugin for Cordova iOS and Android apps
208 stars 72 forks source link

Crash when use cyrillic (non-latin) title #36

Closed KODerFunk closed 8 years ago

KODerFunk commented 8 years ago

Crash in encodeString https://github.com/EddyVerbruggen/cordova-plugin-actionsheet/blob/master/src/ios/ActionSheet.m#L67

Fix in project localy by change NSISOLatin1StringEncoding => NSUTF8StringEncoding in cStringUsingEncoding call.

Used title: Откуда взять фото?

EddyVerbruggen commented 8 years ago

Interesting - if I use that I don't get Откуда взять фото? but an encoded version.. I had to change this for #35, but indeed yours crashes. Any ideas?

KODerFunk commented 8 years ago

Try spain words with my trick (without NSISOLatin1StringEncoding). If it work — it must be fixed!)

EddyVerbruggen commented 8 years ago

I did but it didn't work for me. Perphaps I have the syntax wrong?

KODerFunk commented 8 years ago

Can it been auto-tested? I can prepare detailed report, if you want

EddyVerbruggen commented 8 years ago

I'm simply trying it like this:

        function testShareSheet() {
          var options = {
            'title': 'Откуда взять фото?',
            'buttonLabels': ['Español', 'Inglés'],
            'addCancelButtonWithLabel': 'What\'s Español?',
            'addDestructiveButtonWithLabel' : 'Remove Inglés'
          };
          window.plugins.actionsheet.show(options, function(){});
        };

And the result with

[NSString stringWithCString:[input cStringUsingEncoding:NSUTF8StringEncoding] encoding:NSUTF8StringEncoding];

(which is the same as not encoding it at all) is:

screen shot 2016-02-16 at 19 15 53

Do you see a similar result?

I'm going to roll my last change back so your case works again, but Spanish will break again. Ideas?

KODerFunk commented 8 years ago

I try use your options in my app http://take.ms/NduTs with my dirty-fix:

my UTF8-trick

Then I return NSISOLatin1StringEncoding, cordova run ios ..., tap..tap...tap, crash! Crashshot: http://take.ms/oNPsj

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[NSString stringWithCString:encoding:]: NULL cString'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010fe8de65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x00000001132e8deb objc_exception_throw + 48
    2   CoreFoundation                      0x000000010fe8dd9d +[NSException raise:format:] + 205
    3   Foundation                          0x0000000112eaedc4 +[NSString stringWithCString:encoding:] + 84
    4   *                                   0x000000010fb23803 -[ActionSheet encodeString:] + 147
    5   *                                   0x000000010fb22cbb __20-[ActionSheet show:]_block_invoke + 91
    6   libdispatch.dylib                   0x0000000113ad1e5d _dispatch_call_block_and_release + 12
    7   libdispatch.dylib                   0x0000000113af249b _dispatch_client_callout + 8
    8   libdispatch.dylib                   0x0000000113adabef _dispatch_root_queue_drain + 1829
    9   libdispatch.dylib                   0x0000000113ada4c5 _dispatch_worker_thread3 + 111
    10  libsystem_pthread.dylib             0x0000000113e2a68f _pthread_wqthread + 1129
    11  libsystem_pthread.dylib             0x0000000113e28365 start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

Could this be due to the fact that all my sources utf8-encoded and <meta charset="utf-8" /> in index.html/head? System and phone locale is ru/ru-RU.

EddyVerbruggen commented 8 years ago

Ha, that's it!

You just need to add <meta charset="utf-8" /> meta tag and all encoding is just fine. So the 2.2.2 release should work fine for you with that tag added, thanks for the pointer!

KODerFunk commented 8 years ago

Thank You, @EddyVerbruggen!

martinjbaker commented 8 years ago

Not working for me with 2.2.2. I have <meta charset="utf-8" /> in index.html and any non-ASCII characters in buttonLabels are crashing the app. I have bullet points to denote which option is currently active.

buttonLabels: ['Closing Date', '• Average Critic Rating •']
EddyVerbruggen commented 8 years ago

@martinjbaker Works fine on my sim and device (see screenshot).

Can you try removing the iOS platform and adding it again, same for the plugin? And make sure the html/js files are UTF-8 encoded as well.

screen shot 2016-02-19 at 20 25 47
martinjbaker commented 8 years ago

Yep that fixed it, thanks.