diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 145b4940..306751c9 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -68,6 +68,10 @@ + + + + diff --git a/app/src/main/java/io/lbry/browser/utils/LbryUri.java b/app/src/main/java/io/lbry/browser/utils/LbryUri.java index 94458cfa..7b543bb6 100644 --- a/app/src/main/java/io/lbry/browser/utils/LbryUri.java +++ b/app/src/main/java/io/lbry/browser/utils/LbryUri.java @@ -18,7 +18,7 @@ public class LbryUri { public static final int CLAIM_ID_MAX_LENGTH = 40; private static final String REGEX_PART_PROTOCOL = "^((?:lbry://|https://)?)"; - private static final String REGEX_PART_HOST = "((?:open.lbry.com/)?)"; + private static final String REGEX_PART_HOST = "((?:open.lbry.com/|lbry.tv/|lbry.lat/|lbry.fr/|lbry.in/)?)"; private static final String REGEX_PART_STREAM_OR_CHANNEL_NAME = "([^:$#/]*)"; private static final String REGEX_PART_MODIFIER_SEPARATOR = "([:$#]?)([^/]*)"; private static final String QUERY_STRING_BREAKER = "^([\\S]+)([?][\\S]*)"; @@ -128,9 +128,14 @@ public class LbryUri { boolean isChannel = includesChannel && Helper.isNullOrEmpty(possibleStreamName); String channelName = includesChannel && streamOrChannelName.length() > 1 ? streamOrChannelName.substring(1) : null; - // It would have thrown already on the RegEx parser if protocol value was incorrect - // open.lbry.com uses ':' as ModSeparators while lbry:// expects '#' - if (components.get(1).equals("open.lbry.com/")) { + /* + * It would have thrown already on the RegEx parser if protocol value was incorrect + * or HTTPS host was unknown to us. + * + * [https://] hosts use ':' as ModSeparators while [lbry://] protocol expects '#' + */ + + if (!components.get(1).isEmpty()) { if (primaryModSeparator.equals(":")) primaryModSeparator = "#"; if (secondaryModSeparator.equals(":")) diff --git a/app/src/test/java/io/lbry/browser/utils/LbryUriTest.java b/app/src/test/java/io/lbry/browser/utils/LbryUriTest.java new file mode 100644 index 00000000..b9a82cf0 --- /dev/null +++ b/app/src/test/java/io/lbry/browser/utils/LbryUriTest.java @@ -0,0 +1,84 @@ +package io.lbry.browser.utils; + +import org.junit.Before; +import org.junit.Test; + +import io.lbry.browser.exceptions.LbryUriException; + +import static org.junit.Assert.assertEquals; + +public class LbryUriTest { + private LbryUri expected; + + /* + * Create an LbryUri object and assign fields manually using class methods. This object will be + * compared with LbryUri.parse() returned object on each test. + */ + @Before + public void createExpected() { + expected = new LbryUri(); + expected.setChannelName("@lbry"); + expected.setStreamName("lbryturns4"); + + try { + LbryUri.UriModifier primaryMod = LbryUri.UriModifier.parse("#", "3f"); + LbryUri.UriModifier secondaryMod = LbryUri.UriModifier.parse("#", "6"); + expected.setChannelClaimId(primaryMod.getClaimId()); + expected.setStreamClaimId(secondaryMod.getClaimId()); + } catch (LbryUriException e) { + e.printStackTrace(); + } + } + + @Test + public void parseOpenLbryComWithChannel() { + LbryUri obtained = new LbryUri(); + + try { + obtained = LbryUri.parse("https://open.lbry.com/@lbry:3f/lbryturns4:6",false); + } catch (LbryUriException e) { + e.printStackTrace(); + } + + assertEquals(expected, obtained); + } + + @Test + public void parseLbryTvWithChannel() { + LbryUri obtained = new LbryUri(); + + try { + obtained = LbryUri.parse("https://lbry.tv/@lbry:3f/lbryturns4:6",false); + } catch (LbryUriException e) { + e.printStackTrace(); + } + + assertEquals(expected, obtained); + } + + @Test + public void parseLbryAlterWithChannel() { + LbryUri obtained = new LbryUri(); + + try { + obtained = LbryUri.parse("https://lbry.lat/@lbry:3f/lbryturns4:6",false); + } catch (LbryUriException e) { + e.printStackTrace(); + } + + assertEquals(expected, obtained); + } + + @Test + public void parseLbryProtocolWithChannel() { + LbryUri obtained = new LbryUri(); + + try { + obtained = LbryUri.parse("lbry://@lbry#3f/lbryturns4#6",false); + } catch (LbryUriException e) { + e.printStackTrace(); + } + + assertEquals(expected, obtained); + } +} \ No newline at end of file