Skip to content

Commit

Permalink
Improve wiki link handling (#1184)
Browse files Browse the repository at this point in the history
* handle wiki links with dashes and index wiki page

* properly handle w vs wiki and links with wiki in it twice

* remove beginning and end of line tokens from wiki regex

* optimize wiki regex
  • Loading branch information
patrickdemers6 committed Nov 2, 2022
1 parent 0cab966 commit 28ca5e6
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class LinkResolverActivity extends AppCompatActivity {
private static final String IMGUR_ALBUM_PATTERN = "/(album|a)/\\w+/?";
private static final String IMGUR_IMAGE_PATTERN = "/\\w+/?";
private static final String RPAN_BROADCAST_PATTERN = "/rpan/r/[\\w-]+/\\w+/?\\w+/?";
private static final String WIKI_PATTERN = "/[rR]/[\\w-]+/(wiki|w)?(?:/\\w+)+";
private static final String WIKI_PATTERN = "/[rR]/[\\w-]+/(wiki|w)(?:/[\\w-]+)*";
private static final String GOOGLE_AMP_PATTERN = "/amp/s/amp.reddit.com/.*";
private static final String STREAMABLE_PATTERN = "/\\w+/?";

Expand Down Expand Up @@ -206,7 +206,17 @@ private void handleUri(Uri uri) {
deepLinkError(uri);
}
} else if (path.matches(WIKI_PATTERN)) {
final String wikiPage = path.substring(path.lastIndexOf("/wiki/") + 6);
String[] pathSegments = path.split("/");
String wikiPage;
if (pathSegments.length == 4) {
wikiPage = "index";
} else {
int lengthThroughWiki = 0;
for (int i = 1; i <= 3; ++i) {
lengthThroughWiki += pathSegments[i].length() + 1;
}
wikiPage = path.substring(lengthThroughWiki);
}
Intent intent = new Intent(this, WikiActivity.class);
intent.putExtra(WikiActivity.EXTRA_SUBREDDIT_NAME, segments.get(1));
intent.putExtra(WikiActivity.EXTRA_WIKI_PATH, wikiPage);
Expand Down

0 comments on commit 28ca5e6

Please sign in to comment.