cordova-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shingo Toda (JIRA)" <>
Subject [jira] [Created] (CB-7906) App crashes when find() is called with undefined desiredField members
Date Thu, 30 Oct 2014 05:40:33 GMT
Shingo Toda created CB-7906:

             Summary: App crashes when find() is called with undefined desiredField members
                 Key: CB-7906
             Project: Apache Cordova
          Issue Type: Bug
          Components: Docs, iOS, Plugin Contacts
    Affects Versions: 3.6.0
         Environment: iOS7,8
            Reporter: Shingo Toda
            Priority: Minor

Apps crash when find() is called with undefined members of ContactFieldType.
For example, the following code sets desiredFields to {{xx}} or {{yyy}} which are actually
not defined in ContactFieldType.

options.desiredFields = [navigator.contacts.fieldType.xx, navigator.contacts.fieldType.yyy];
var fields = [navigator.contacts.fieldType.displayName,];
navigator.contacts.find(fields, onSuccess, onError, options);

In Objective-C code, those undefined members are turned into {{NSNull}} object. Therefore
{{calcReturnFields}} method receives {{fieldArray}} which contains {{NSNull}} objects, then
analyses {{fieldStr}} NSString object which is actually {{NSNull}} at {{[fieldStr componentsSeparatedByString:@"."]}}
and eventually an app crashes.

I tweaked {{calcReturnFields}} method to ignore {{NSNull}} object as below and this looks
working fine.

        for (id i in fieldsArray) {
            NSMutableArray* keys = nil;
            NSString* fieldStr = nil;
            if ([i isKindOfClass:[NSNumber class]]) {
                fieldStr = [i stringValue];
            // ST modified start
            } else if([i isEqual:[NSNull null]]){
            // ST modified end
            } else {
                fieldStr = i;

By this modification, all invalid desiredField types are ignored and those types could be
thought to be "not found". In my opinion, this behaviour would make sense to developer as
{{find()}} is called with dodgy desiredField parameters then those types shouldn't be included
in the returned contact data. As far as I know, at least {{find()}} for Android behaves like

By the way, I couldn't see supported parameters for {{desiredField}} in document. If I look
at {{ContactFieldType.js}}, those members are populated from {{Contact}}, {{ContactAddress}},
etc.. It would be nice to clearly describe all supported types.

This message was sent by Atlassian JIRA

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message