Dbrant has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/377759 )
Change subject: Correctly handle links with non-http schemes. ...................................................................... Correctly handle links with non-http schemes. This fixes a couple of issues: - URLs with a scheme that wasn't "http" or "https" were being incorrectly rewritten with a prefix of "http://wp..." - When querying intents for the activity chooser that handles external links, we were incorrectly querying intents for the "http" scheme. This fixes the querying to use the scheme specified in the original Uri. Bug: T175586 Change-Id: I299d9093639ef61ea0401b2d1e475cd5af1df3cf --- M app/src/main/java/org/wikipedia/page/LinkHandler.java M app/src/main/java/org/wikipedia/util/ShareUtil.java 2 files changed, 21 insertions(+), 7 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia refs/changes/59/377759/1 diff --git a/app/src/main/java/org/wikipedia/page/LinkHandler.java b/app/src/main/java/org/wikipedia/page/LinkHandler.java index 3a644fa..7a2aa1e 100644 --- a/app/src/main/java/org/wikipedia/page/LinkHandler.java +++ b/app/src/main/java/org/wikipedia/page/LinkHandler.java @@ -13,6 +13,9 @@ import org.wikipedia.dataclient.WikiSite; import org.wikipedia.util.UriUtil; +import java.util.Arrays; +import java.util.List; + import static org.wikipedia.util.UriUtil.decodeURL; import static org.wikipedia.util.UriUtil.handleExternalLink; @@ -20,6 +23,9 @@ * Handles any html links coming from a {@link org.wikipedia.page.PageFragment} */ public abstract class LinkHandler implements CommunicationBridge.JSEventListener, LinkMovementMethodExt.UrlHandler { + private static final List<String> KNOWN_SCHEMES + = Arrays.asList("http", "https", "geo", "file", "content"); + @NonNull private final Context context; public LinkHandler(@NonNull Context context) { @@ -48,18 +54,26 @@ @Override public void onUrlClick(@NonNull String href, @Nullable String titleString) { - // other domain links if (href.startsWith("//")) { + // for URLs without an explicit scheme, add our default scheme explicitly. href = getWikiSite().scheme() + ":" + href; } Uri uri = Uri.parse(href); - if (!href.startsWith("http:") && !href.startsWith("https:")) { + + boolean knownScheme = false; + for (String scheme : KNOWN_SCHEMES) { + if (href.startsWith(scheme + ":")) { + knownScheme = true; + } + } + if (!knownScheme) { + // for URLs without a known scheme, add our default scheme explicitly. uri = uri.buildUpon() - .scheme(getWikiSite().scheme()) - .authority(getWikiSite().authority()) - .path(href) - .build(); + .scheme(getWikiSite().scheme()) + .authority(getWikiSite().authority()) + .path(href) + .build(); } Log.d("Wikipedia", "Link clicked was " + uri.toString()); diff --git a/app/src/main/java/org/wikipedia/util/ShareUtil.java b/app/src/main/java/org/wikipedia/util/ShareUtil.java index 6df807c..7599e9a 100644 --- a/app/src/main/java/org/wikipedia/util/ShareUtil.java +++ b/app/src/main/java/org/wikipedia/util/ShareUtil.java @@ -201,7 +201,7 @@ List<Intent> intents = new ArrayList<>(); Intent queryIntent = new Intent(targetIntent); if (targetIntent.getAction().equals(Intent.ACTION_VIEW)) { - queryIntent.setData(Uri.parse("http://example.com")); + queryIntent.setData(targetIntent.getData()); } for (ResolveInfo intentActivity : queryIntentActivities(queryIntent, context)) { if (!isIntentActivityBlacklisted(intentActivity, packageNameBlacklistRegex)) { -- To view, visit https://gerrit.wikimedia.org/r/377759 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I299d9093639ef61ea0401b2d1e475cd5af1df3cf Gerrit-PatchSet: 1 Gerrit-Project: apps/android/wikipedia Gerrit-Branch: master Gerrit-Owner: Dbrant <dbr...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits