From d10b1e21561d150d7967dc6d80bf9b76fc5770eb Mon Sep 17 00:00:00 2001 From: Rad Azzouz Date: Thu, 5 Feb 2015 16:13:55 -0500 Subject: [PATCH] [FIXED] Fixed issue that was causing the 1Password Beta Extension to crash when attempting to fill into UIWebViews in third party apps using. This issue is old the collected page details was never valid for `UIWebViews`. This fix will enable the new filling brain from the 1Password 5.3 betas to work properly. --- OnePasswordExtension.m | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/OnePasswordExtension.m b/OnePasswordExtension.m index 9455bca..8c01174 100644 --- a/OnePasswordExtension.m +++ b/OnePasswordExtension.m @@ -408,7 +408,16 @@ - (void)findLoginIn1PasswordWithURLString:(NSString *)URLString collectedPageDet completion(NO, URLStringError); } - NSDictionary *item = @{ AppExtensionVersionNumberKey : VERSION_NUMBER, AppExtensionURLStringKey : URLString, AppExtensionWebViewPageDetails : collectedPageDetails }; + NSError *jsonError = nil; + NSData *data = [collectedPageDetails dataUsingEncoding:NSUTF8StringEncoding]; + NSDictionary *collectedPageDetailsDictionary = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&jsonError]; + + if (collectedPageDetailsDictionary.count == 0) { + NSLog(@"Failed to parse JSON collected page details: %@", jsonError); + completion(NO, jsonError); + } + + NSDictionary *item = @{ AppExtensionVersionNumberKey : VERSION_NUMBER, AppExtensionURLStringKey : URLString, AppExtensionWebViewPageDetails : collectedPageDetailsDictionary }; UIActivityViewController *activityViewController = [self activityViewControllerForItem:item viewController:forViewController sender:sender typeIdentifier:kUTTypeAppExtensionFillWebViewAction]; activityViewController.completionWithItemsHandler = ^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) { @@ -519,7 +528,7 @@ - (void)executeFillScript:(NSString *)fillScript inWebView:(id)webView completio var c=b.ownerDocument.createEvent('HTMLEvents');B(b,'keydown');B(b,'keyup');B(b,'keypress');c.initEvent('input',!0,!0);b.dispatchEvent(c);a.initEvent('change',!0,!0);b.dispatchEvent(a);b.blur()});return{documentUUID:d,title:e.title,url:u.location.href,forms:function(a){var b={};a.forEach(function(a){b[a.opid]=a});return b}(C),fields:z,collectedTimestamp:(new Date).getTime()}};document.elementForOPID=D;function B(e,d){var f;f=e.ownerDocument.createEvent('KeyboardEvent');f.initKeyboardEvent?f.initKeyboardEvent(d,!0,!0):f.initKeyEvent&&f.initKeyEvent(d,!0,!0,null,!1,!1,!1,!1,0,0);e.dispatchEvent(f)}function y(e,d){var f;f='';3===d.nodeType?f=d.nodeValue:1===d.nodeType&&(f=d.innerText||d.textContent);var g=null;f&&(g=f.toLowerCase().replace(/\\s/mg,'').replace(/[~`!@$%^&*()\\-_+=:;'\"\\[\\]|\\\\,<.>\\/?]/mg,''),g=0