jenkins-bot has submitted this change and it was merged.

Change subject: Ignore encoding malformations when decoding URL fragments.
......................................................................


Ignore encoding malformations when decoding URL fragments.

Search results that come from prefix-search can sometimes contain URL fragments
(links to a section within the article), and it turns out that these fragments
can potentially be formatted incorrectly, and cause URLDecoder to throw an
exception that we weren't handling previously.

Bug: T147754
Change-Id: I568cd472564695da3e9e3d8200eed7b8c7f09fb8
---
M app/src/main/java/org/wikipedia/util/UriUtil.java
1 file changed, 5 insertions(+), 4 deletions(-)

Approvals:
  Mholloway: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/app/src/main/java/org/wikipedia/util/UriUtil.java 
b/app/src/main/java/org/wikipedia/util/UriUtil.java
index 4157026..edc15b4 100644
--- a/app/src/main/java/org/wikipedia/util/UriUtil.java
+++ b/app/src/main/java/org/wikipedia/util/UriUtil.java
@@ -17,7 +17,6 @@
 import org.wikipedia.settings.Prefs;
 import org.wikipedia.zero.WikipediaZeroHandler;
 
-import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
 
 import static 
org.wikipedia.zero.WikipediaZeroHandler.showZeroExitInterstitialDialog;
@@ -29,11 +28,13 @@
      * @param url The URL-encoded string that you wish to decode.
      * @return The decoded string, or the input string if the decoding failed.
      */
-    public static String decodeURL(String url) {
+    @NonNull public static String decodeURL(@NonNull String url) {
         try {
             return URLDecoder.decode(url, "UTF-8");
-        } catch (UnsupportedEncodingException e) {
-            // Inexplicable decoding problem. This shouldn't happen. Return 
the input.
+        } catch (Exception e) {
+            // Swallow any exception, including UnsupportedEncodingException 
(shouldn't happen),
+            // and IllegalArgumentException (can happen with malformed 
encoding), and just return
+            // the original string.
             Log.d("Wikipedia", "URL decoding failed. String was: " + url);
             return url;
         }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I568cd472564695da3e9e3d8200eed7b8c7f09fb8
Gerrit-PatchSet: 1
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Dbrant <dbr...@wikimedia.org>
Gerrit-Reviewer: BearND <bsitzm...@wikimedia.org>
Gerrit-Reviewer: Brion VIBBER <br...@wikimedia.org>
Gerrit-Reviewer: Mholloway <mhollo...@wikimedia.org>
Gerrit-Reviewer: Niedzielski <sniedziel...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to