From 84bb014557da21455a56c3c8885737464991b903 Mon Sep 17 00:00:00 2001 From: Javi Rueda Date: Thu, 29 Jul 2021 00:55:45 +0200 Subject: [PATCH] Accept colon or octoshape as claimID modifier character and add unit tests --- .../java/io/lbry/browser/utils/LbryUri.java | 18 ++------------- .../io/lbry/browser/utils/LbryUriTest.java | 22 +++++++++++++------ 2 files changed, 17 insertions(+), 23 deletions(-) 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 1570ab96..3e0113fa 100644 --- a/app/src/main/java/io/lbry/browser/utils/LbryUri.java +++ b/app/src/main/java/io/lbry/browser/utils/LbryUri.java @@ -141,20 +141,6 @@ 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 - * 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(":")) - secondaryModSeparator = "#"; - } - if (includesChannel) { if (Helper.isNullOrEmpty(channelName)) { throw new LbryUriException("No channel name after @."); @@ -329,9 +315,9 @@ public class LbryUri { throw new LbryUriException(String.format("No modifier provided after separator %s", modSeparator)); } - if ("#".equals(modSeparator)) { + if ("#".equals(modSeparator) || ":".equals(modSeparator)) { claimId = modValue; - } else if (":".equals(modSeparator)) { + } else if ("*".equals(modSeparator)) { claimSequence = Helper.parseInt(modValue, -1); } else if ("$".equals(modSeparator)) { bidPosition = Helper.parseInt(modValue, -1); diff --git a/app/src/test/java/io/lbry/browser/utils/LbryUriTest.java b/app/src/test/java/io/lbry/browser/utils/LbryUriTest.java index 45c0c943..cc427e30 100644 --- a/app/src/test/java/io/lbry/browser/utils/LbryUriTest.java +++ b/app/src/test/java/io/lbry/browser/utils/LbryUriTest.java @@ -10,6 +10,7 @@ import static org.junit.Assert.assertEquals; public class LbryUriTest { private LbryUri expected; + private LbryUri expectedOctoshape; /* * Create an LbryUri object and assign fields manually using class methods. This object will be @@ -18,14 +19,21 @@ public class LbryUriTest { @Before public void createExpected() { expected = new LbryUri(); + expectedOctoshape = new LbryUri(); expected.setChannelName("@lbry"); expected.setStreamName("lbryturns4"); + expectedOctoshape.setChannelName("@lbry"); + expectedOctoshape.setStreamName("lbryturns4"); try { - LbryUri.UriModifier primaryMod = LbryUri.UriModifier.parse("#", "3f"); - LbryUri.UriModifier secondaryMod = LbryUri.UriModifier.parse("#", "6"); + LbryUri.UriModifier primaryMod = LbryUri.UriModifier.parse(":", "3f"); + LbryUri.UriModifier secondaryMod = LbryUri.UriModifier.parse(":", "6"); + LbryUri.UriModifier primaryModOctoshape = LbryUri.UriModifier.parse("#", "3f"); + LbryUri.UriModifier secondaryModOctoshape = LbryUri.UriModifier.parse("#", "6"); expected.setChannelClaimId(primaryMod.getClaimId()); expected.setStreamClaimId(secondaryMod.getClaimId()); + expectedOctoshape.setChannelClaimId(primaryModOctoshape.getClaimId()); + expectedOctoshape.setStreamClaimId(secondaryModOctoshape.getClaimId()); } catch (LbryUriException e) { e.printStackTrace(); } @@ -71,7 +79,7 @@ public class LbryUriTest { } @Test - public void parseLbryProtocolWithChannel() { + public void parseLbryProtocolWithChannelOctoshape() { LbryUri obtained = new LbryUri(); try { @@ -80,12 +88,12 @@ public class LbryUriTest { e.printStackTrace(); } - assertEquals(expected, obtained); + assertEquals(expectedOctoshape, obtained); } @Test public void parseLbryProtocolOnlyChannel() { - LbryUri expectedForChannel = sinthesizeExpected(); + LbryUri expectedForChannel = sinthesizeExpectedChannelOctoshape(); LbryUri obtained = new LbryUri(); @@ -100,7 +108,7 @@ public class LbryUriTest { @Test public void parseLbryTvProtocolOnlyChannel() { - LbryUri expectedForChannel = sinthesizeExpected(); + LbryUri expectedForChannel = sinthesizeExpectedChannelOctoshape(); LbryUri obtained = new LbryUri(); @@ -192,7 +200,7 @@ public class LbryUriTest { } @NotNull - private LbryUri sinthesizeExpected() { + private LbryUri sinthesizeExpectedChannelOctoshape() { LbryUri expectedForChannel = new LbryUri(); expectedForChannel.setChannelName("@UCBerkeley"); expectedForChannel.setChannel(true); -- 2.45.2