Fjalapeno has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/220695

Change subject: Fix crash bug due to nil title text. Bug: T103737
......................................................................

Fix crash bug due to nil title text.
Bug: T103737

Multiple safety nets:
when exporting history item, only set keys with non-nil values
when adding history item, do not add history items with nil text
add parameter asset to display page method for the pagetitle.text
add length check before displaying article
show error if we download an article without a title (added error string)

Change-Id: Ia798c2c64984ddc6cb7d418ebf9649cc2cadb0e5
---
M MediaWikiKit/MediaWikiKit/MWKHistoryEntry.m
M MediaWikiKit/MediaWikiKit/MWKUserDataStore.m
M Wikipedia/View Controllers/WebView/WebViewController.m
M Wikipedia/en.lproj/Localizable.strings
M Wikipedia/qqq.lproj/Localizable.strings
5 files changed, 30 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/apps/ios/wikipedia 
refs/changes/95/220695/1

diff --git a/MediaWikiKit/MediaWikiKit/MWKHistoryEntry.m 
b/MediaWikiKit/MediaWikiKit/MWKHistoryEntry.m
index fdd7dab..15e7699 100644
--- a/MediaWikiKit/MediaWikiKit/MWKHistoryEntry.m
+++ b/MediaWikiKit/MediaWikiKit/MWKHistoryEntry.m
@@ -8,6 +8,7 @@
 
 #import "MediaWikiKit.h"
 #import "WikipediaAppUtils.h"
+#import "NSMutableDictionary+WMFMaybeSet.h"
 
 @interface MWKHistoryEntry ()
 
@@ -67,13 +68,13 @@
 - (id)dataExport {
     NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
 
-    dict[@"domain"]          = self.site.domain;
-    dict[@"language"]        = self.site.language;
-    dict[@"title"]           = self.title.dataBaseKey;
-    dict[@"date"]            = [self iso8601DateString:self.date];
-    dict[@"discoveryMethod"] = [MWKHistoryEntry 
stringForDiscoveryMethod:self.discoveryMethod];
-    dict[@"scrollPosition"]  = @(self.scrollPosition);
-
+    [dict wmf_maybeSetObject:self.site.domain forKey:@"domain"];
+    [dict wmf_maybeSetObject:self.site.language forKey:@"language"];
+    [dict wmf_maybeSetObject:self.title.dataBaseKey forKey:@"title"];
+    [dict wmf_maybeSetObject:[self iso8601DateString:self.date] 
forKey:@"date"];
+    [dict wmf_maybeSetObject:[MWKHistoryEntry 
stringForDiscoveryMethod:self.discoveryMethod] forKey:@"discoveryMethod"];
+    [dict wmf_maybeSetObject:@(self.scrollPosition) forKey:@"scrollPosition"];
+    
     return [NSDictionary dictionaryWithDictionary:dict];
 }
 
diff --git a/MediaWikiKit/MediaWikiKit/MWKUserDataStore.m 
b/MediaWikiKit/MediaWikiKit/MWKUserDataStore.m
index 6acfe09..f87c424 100644
--- a/MediaWikiKit/MediaWikiKit/MWKUserDataStore.m
+++ b/MediaWikiKit/MediaWikiKit/MWKUserDataStore.m
@@ -88,9 +88,9 @@
 }
 
 - (void)updateHistory:(MWKTitle*)title 
discoveryMethod:(MWKHistoryDiscoveryMethod)discoveryMethod {
-    if (title == nil) {
-        @throw [NSException exceptionWithName:@"MWKUserDataStoreException"
-                                       reason:@"updateHistory called with null 
title" userInfo:@{}];
+    if (title.text == nil) {
+        //Weird, should be text hereā€¦ if not we can't go forward. Just not 
going to update the history.
+        return;
     }
     MWKHistoryEntry* entry = [self.historyList entryForTitle:title];
     if (entry) {
diff --git a/Wikipedia/View Controllers/WebView/WebViewController.m 
b/Wikipedia/View Controllers/WebView/WebViewController.m
index b66e1aa..9f9b1af 100644
--- a/Wikipedia/View Controllers/WebView/WebViewController.m
+++ b/Wikipedia/View Controllers/WebView/WebViewController.m
@@ -1385,6 +1385,9 @@
 
 - (void)retrieveArticleForPageTitle:(MWKTitle*)pageTitle
                     discoveryMethod:(MWKHistoryDiscoveryMethod)discoveryMethod 
{
+    
+    NSParameterAssert(pageTitle.text);
+    
     // Cancel certain in-progress fetches.
     [self cancelSearchLoading];
     [self cancelArticleLoading];
@@ -1466,6 +1469,13 @@
 
                 self.isFetchingArticle = NO;
 
+                if([article.title.text length] == 0){
+                    
+                    [self 
showAlert:MWLocalizedString(@"article-unable-to-load-article", nil) 
type:ALERT_TYPE_TOP duration:2];
+
+                    return;
+                }
+                
                 // Update the toc and web view.
                 [self displayArticle:article.title];
 
@@ -1477,6 +1487,7 @@
             {
                 self.isFetchingArticle = NO;
 
+                //attempt to display article from cache
                 [self displayArticle:article.title];
 
                 NSString* errorMsg = error.localizedDescription;
@@ -1502,7 +1513,6 @@
                     TopMenuTextFieldContainer* textFieldContainer = 
[ROOT.topMenuViewController getNavBarItem:NAVBAR_TEXT_FIELD];
                     textFieldContainer.textField.placeholder = 
MWLocalizedString(@"search-field-placeholder-text-zero", nil);
 
-                    //[self showAlert:title type:ALERT_TYPE_TOP duration:2];
                     NSString* title = banner[@"message"];
                     self.zeroStatusLabel.text            = title;
                     self.zeroStatusLabel.padding         = UIEdgeInsetsMake(3, 
10, 3, 10);
@@ -1637,6 +1647,12 @@
 #pragma mark Display article from data store
 
 - (void)displayArticle:(MWKTitle*)title {
+    
+    NSParameterAssert(title.text);
+    if([title.text length] == 0){
+        return;
+    }
+
     MWKArticle* article = [self.session.dataStore articleWithTitle:title];
     self.session.currentArticle = article;
 
diff --git a/Wikipedia/en.lproj/Localizable.strings 
b/Wikipedia/en.lproj/Localizable.strings
index 990b872..e779b6e 100644
--- a/Wikipedia/en.lproj/Localizable.strings
+++ b/Wikipedia/en.lproj/Localizable.strings
@@ -5,6 +5,7 @@
 "article-languages-filter-placeholder" = "Language Filter";
 "article-read-more-title" = "Read more";
 "article-unable-to-load-section" = "Unable to load this section. Try 
refreshing the article to see if it fixes the problem.";
+"article-unable-to-load-article" = "Unable to load article.";
 
 "info-box-title" = "Quick facts";
 "info-box-close-text" = "Close";
diff --git a/Wikipedia/qqq.lproj/Localizable.strings 
b/Wikipedia/qqq.lproj/Localizable.strings
index 6429af8..644c13c 100644
--- a/Wikipedia/qqq.lproj/Localizable.strings
+++ b/Wikipedia/qqq.lproj/Localizable.strings
@@ -17,6 +17,7 @@
 "article-languages-label" = "Header label for per-article language selector 
screen.\n{{Identical|Choose language}}";
 "article-languages-cancel" = "Button text for dismissing the language selector 
screen.\n{{Identical|Cancel}}";
 "article-languages-downloading" = "Alert text shown when obtaining list of 
languages in which an article is available";
+"article-unable-to-load-article" = "Alert text shown when unable to load an 
article";
 "article-languages-filter-placeholder" = "Filter languages text box 
placeholder text.";
 "article-read-more-title" = "The text that is displayed before the read more 
section at the bottom of an article\n{{Identical|Read more}}";
 "article-unable-to-load-section" = "Displayed within the article content when 
a section fails to render for some reason.";

-- 
To view, visit https://gerrit.wikimedia.org/r/220695
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia798c2c64984ddc6cb7d418ebf9649cc2cadb0e5
Gerrit-PatchSet: 1
Gerrit-Project: apps/ios/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Fjalapeno <cfl...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to