From 89038e72d7783b6b94315e5da472022362139953 Mon Sep 17 00:00:00 2001 From: Nikita Matrosov Date: Mon, 10 Oct 2016 12:02:17 +0300 Subject: [PATCH] CB-11975 iOS: Search on contacts' id with number type There was crash when user passed id of numeric type --- src/ios/CDVContacts.m | 4 +++- tests/tests.js | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/ios/CDVContacts.m b/src/ios/CDVContacts.m index d5dd9580..14fce2c8 100644 --- a/src/ios/CDVContacts.m +++ b/src/ios/CDVContacts.m @@ -330,7 +330,9 @@ - (void)search:(CDVInvokedUrlCommand*)command NSArray* desiredFields = nil; if (![findOptions isKindOfClass:[NSNull class]]) { id value = nil; - filter = (NSString*)[findOptions objectForKey:@"filter"]; + id filterValue = [findOptions objectForKey:@"filter"]; + BOOL filterValueIsNumber = [filterValue isKindOfClass:[NSNumber class]]; + filter = filterValueIsNumber ? [filterValue stringValue] : (NSString *) filterValue; value = [findOptions objectForKey:@"multiple"]; if ([value isKindOfClass:[NSNumber class]]) { // multiple is a boolean that will come through as an NSNumber diff --git a/tests/tests.js b/tests/tests.js index 1f06cc49..6d0ef543 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -281,6 +281,27 @@ exports.defineAutoTests = function() { }; specContext.contactObj.save(onSuccessSave, fail.bind(null, done)); }); + it("contacts.spec.7.2 should find contact despite id isn't string ", function(done) { + if (isWindows || isWindowsPhone8 || isIOSPermissionBlocked) { + pending(); + } + var testDisplayName = "testContact"; + var specContext = this; + specContext.contactObj = new Contact(); + specContext.contactObj.displayName = testDisplayName; + var win = function(contactResult) { + expect(contactResult.length > 0).toBe(true); + done(); + }; + var onSuccessSave = function(savedContact) { + specContext.contactObj = savedContact; + var options = new ContactFindOptions(); + options.filter = savedContact.id; + options.multiple = true; + navigator.contacts.find(["id"], win, fail.bind(null, done), options); + }; + specContext.contactObj.save(onSuccessSave, fail.bind(null, done)); + }); }); });