Merge pull request #1208 from lbryio/claimid-modifier-char
Accept colon or octoshape as claimID modifier character
This commit is contained in:
commit
2ad49ca281
2 changed files with 17 additions and 23 deletions
|
@ -141,20 +141,6 @@ public class LbryUri {
|
||||||
boolean isChannel = includesChannel && Helper.isNullOrEmpty(possibleStreamName);
|
boolean isChannel = includesChannel && Helper.isNullOrEmpty(possibleStreamName);
|
||||||
String channelName = includesChannel && streamOrChannelName.length() > 1 ? streamOrChannelName.substring(1) : null;
|
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 (includesChannel) {
|
||||||
if (Helper.isNullOrEmpty(channelName)) {
|
if (Helper.isNullOrEmpty(channelName)) {
|
||||||
throw new LbryUriException("No channel name after @.");
|
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));
|
throw new LbryUriException(String.format("No modifier provided after separator %s", modSeparator));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("#".equals(modSeparator)) {
|
if ("#".equals(modSeparator) || ":".equals(modSeparator)) {
|
||||||
claimId = modValue;
|
claimId = modValue;
|
||||||
} else if (":".equals(modSeparator)) {
|
} else if ("*".equals(modSeparator)) {
|
||||||
claimSequence = Helper.parseInt(modValue, -1);
|
claimSequence = Helper.parseInt(modValue, -1);
|
||||||
} else if ("$".equals(modSeparator)) {
|
} else if ("$".equals(modSeparator)) {
|
||||||
bidPosition = Helper.parseInt(modValue, -1);
|
bidPosition = Helper.parseInt(modValue, -1);
|
||||||
|
|
|
@ -10,6 +10,7 @@ import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
public class LbryUriTest {
|
public class LbryUriTest {
|
||||||
private LbryUri expected;
|
private LbryUri expected;
|
||||||
|
private LbryUri expectedOctoshape;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create an LbryUri object and assign fields manually using class methods. This object will be
|
* Create an LbryUri object and assign fields manually using class methods. This object will be
|
||||||
|
@ -18,14 +19,21 @@ public class LbryUriTest {
|
||||||
@Before
|
@Before
|
||||||
public void createExpected() {
|
public void createExpected() {
|
||||||
expected = new LbryUri();
|
expected = new LbryUri();
|
||||||
|
expectedOctoshape = new LbryUri();
|
||||||
expected.setChannelName("@lbry");
|
expected.setChannelName("@lbry");
|
||||||
expected.setStreamName("lbryturns4");
|
expected.setStreamName("lbryturns4");
|
||||||
|
expectedOctoshape.setChannelName("@lbry");
|
||||||
|
expectedOctoshape.setStreamName("lbryturns4");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
LbryUri.UriModifier primaryMod = LbryUri.UriModifier.parse("#", "3f");
|
LbryUri.UriModifier primaryMod = LbryUri.UriModifier.parse(":", "3f");
|
||||||
LbryUri.UriModifier secondaryMod = LbryUri.UriModifier.parse("#", "6");
|
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.setChannelClaimId(primaryMod.getClaimId());
|
||||||
expected.setStreamClaimId(secondaryMod.getClaimId());
|
expected.setStreamClaimId(secondaryMod.getClaimId());
|
||||||
|
expectedOctoshape.setChannelClaimId(primaryModOctoshape.getClaimId());
|
||||||
|
expectedOctoshape.setStreamClaimId(secondaryModOctoshape.getClaimId());
|
||||||
} catch (LbryUriException e) {
|
} catch (LbryUriException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -71,7 +79,7 @@ public class LbryUriTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseLbryProtocolWithChannel() {
|
public void parseLbryProtocolWithChannelOctoshape() {
|
||||||
LbryUri obtained = new LbryUri();
|
LbryUri obtained = new LbryUri();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -80,12 +88,12 @@ public class LbryUriTest {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEquals(expected, obtained);
|
assertEquals(expectedOctoshape, obtained);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseLbryProtocolOnlyChannel() {
|
public void parseLbryProtocolOnlyChannel() {
|
||||||
LbryUri expectedForChannel = sinthesizeExpected();
|
LbryUri expectedForChannel = sinthesizeExpectedChannelOctoshape();
|
||||||
|
|
||||||
LbryUri obtained = new LbryUri();
|
LbryUri obtained = new LbryUri();
|
||||||
|
|
||||||
|
@ -100,7 +108,7 @@ public class LbryUriTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseLbryTvProtocolOnlyChannel() {
|
public void parseLbryTvProtocolOnlyChannel() {
|
||||||
LbryUri expectedForChannel = sinthesizeExpected();
|
LbryUri expectedForChannel = sinthesizeExpectedChannelOctoshape();
|
||||||
|
|
||||||
LbryUri obtained = new LbryUri();
|
LbryUri obtained = new LbryUri();
|
||||||
|
|
||||||
|
@ -192,7 +200,7 @@ public class LbryUriTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private LbryUri sinthesizeExpected() {
|
private LbryUri sinthesizeExpectedChannelOctoshape() {
|
||||||
LbryUri expectedForChannel = new LbryUri();
|
LbryUri expectedForChannel = new LbryUri();
|
||||||
expectedForChannel.setChannelName("@UCBerkeley");
|
expectedForChannel.setChannelName("@UCBerkeley");
|
||||||
expectedForChannel.setChannel(true);
|
expectedForChannel.setChannel(true);
|
||||||
|
|
Loading…
Reference in a new issue