[
https://issues.apache.org/jira/browse/CB-7906?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15020451#comment-15020451
]
ASF GitHub Bot commented on CB-7906:
------------------------------------
GitHub user vladimir-kotikov opened a pull request:
https://github.com/apache/cordova-plugin-contacts/pull/85
CB-7906 Prevent app crash when desiredFields option has undefined items
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/MSOpenTech/cordova-plugin-contacts CB-7906
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/cordova-plugin-contacts/pull/85.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #85
----
commit deda3d83b24f3ae4fd004ee7f75f7b95ab0ca354
Author: Vladimir Kotikov <[email protected]>
Date: 2015-11-21T13:02:53Z
CB-7906 Prevent app crash when desiredFields option has undefined items
----
> App crashes when find() is called with undefined desiredField members
> ---------------------------------------------------------------------
>
> Key: CB-7906
> URL: https://issues.apache.org/jira/browse/CB-7906
> Project: Apache Cordova
> Issue Type: Bug
> Components: Plugin Contacts
> Environment: iOS 7, iOS 8
> Cordova 3.6.0
> Reporter: Shingo Toda
> Labels: documentation-update, iOS, reproduced, triaged
>
> 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.
> {code:javascript}
> options.desiredFields = [navigator.contacts.fieldType.xx,
> navigator.contacts.fieldType.yyy];
> var fields = [navigator.contacts.fieldType.displayName,
> navigator.contacts.fieldType.name];
> navigator.contacts.find(fields, onSuccess, onError, options);
> {code}
> 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.
> {code:title=CDVContact.m}
> 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]]){
> continue;
> // ST modified end
> } else {
> fieldStr = i;
> }
> {code}
> 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 this.
> 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
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]