Skip to content
This repository has been archived by the owner on Jan 12, 2023. It is now read-only.

Commit

Permalink
Bandaid for #1996 - Add null check for urlutils.
Browse files Browse the repository at this point in the history
  • Loading branch information
liuche committed Dec 13, 2017
1 parent 66db374 commit 4c0239a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
11 changes: 10 additions & 1 deletion app/src/main/java/org/mozilla/focus/utils/UrlUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,16 @@ public static boolean isInternalErrorURL(final String url) {
return "data:text/html;charset=utf-8;base64,".equals(url);
}

public static boolean urlsMatchExceptForTrailingSlash(final @NonNull String url1, final @NonNull String url2) {
/**
* Checks that urls are non-null and are the same aside from a trailing slash.
*
* @return true if urls are the same except for trailing slash, or if either url is null.
*/
public static boolean urlsMatchExceptForTrailingSlash(final String url1, final String url2) {
// This is a hack to catch a NPE in issue #26.
if (url1 == null || url2 == null) {
return false;
}
int lengthDifference = url1.length() - url2.length();

if (lengthDifference == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,10 @@ public WebResourceResponse shouldInterceptRequest(final WebView view, final WebR

// Don't block the main frame from being loaded. This also protects against cases where we
// open a link that redirects to another app (e.g. to the play store).
final Uri pageUri = Uri.parse(currentPageURL);
if ((!request.isForMainFrame()) &&
matcher.matches(resourceUri, pageUri)) {
currentPageURL != null &&
matcher.matches(resourceUri, Uri.parse(currentPageURL))) {
// Bandaid for issue #26: currentPageUrl can still be null, and needs to be investigated further.
if (callback != null) {
callback.countBlockedTracker();
}
Expand Down

0 comments on commit 4c0239a

Please sign in to comment.