Decode URL encoded links and unit test it
This commit is contained in:
parent
9ac216504d
commit
e520c3694a
2 changed files with 40 additions and 2 deletions
|
@ -1,5 +1,7 @@
|
||||||
package io.lbry.browser.utils;
|
package io.lbry.browser.utils;
|
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.URLDecoder;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
|
@ -8,6 +10,8 @@ import java.util.regex.Pattern;
|
||||||
import io.lbry.browser.exceptions.LbryUriException;
|
import io.lbry.browser.exceptions.LbryUriException;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import static org.apache.commons.codec.CharEncoding.UTF_8;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class LbryUri {
|
public class LbryUri {
|
||||||
public static final String LBRY_TV_BASE_URL = "https://lbry.tv/";
|
public static final String LBRY_TV_BASE_URL = "https://lbry.tv/";
|
||||||
|
@ -117,10 +121,17 @@ public class LbryUri {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String streamOrChannelName = components.get(2);
|
String streamOrChannelName = null;
|
||||||
|
String possibleStreamName = null;
|
||||||
|
try {
|
||||||
|
// Using java.net.URLDecoder to be able to quickly unit test
|
||||||
|
streamOrChannelName = URLDecoder.decode(components.get(2), UTF_8);
|
||||||
|
possibleStreamName = URLDecoder.decode(components.get(6), UTF_8);
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
String primaryModSeparator = components.get(3);
|
String primaryModSeparator = components.get(3);
|
||||||
String primaryModValue = components.get(4);
|
String primaryModValue = components.get(4);
|
||||||
String possibleStreamName = components.get(6);
|
|
||||||
String secondaryModSeparator = components.get(7);
|
String secondaryModSeparator = components.get(7);
|
||||||
String secondaryModValue = components.get(8);
|
String secondaryModValue = components.get(8);
|
||||||
|
|
||||||
|
|
|
@ -113,6 +113,33 @@ public class LbryUriTest {
|
||||||
assertEquals(expectedForChannel, obtained);
|
assertEquals(expectedForChannel, obtained);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void parseLbryTvWithEncodedChars() {
|
||||||
|
LbryUri obtained = new LbryUri();
|
||||||
|
|
||||||
|
try {
|
||||||
|
obtained = LbryUri.parse("https://lbry.tv/@Content_I_Like:1/DR.-ASTRID-ST%C3%9CCKELBERGER:2",false);
|
||||||
|
} catch (LbryUriException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
expected = new LbryUri();
|
||||||
|
expected.setChannelName("@Content_I_Like");
|
||||||
|
expected.setStreamName("DR.-ASTRID-STÜCKELBERGER");
|
||||||
|
|
||||||
|
try {
|
||||||
|
LbryUri.UriModifier primaryMod = LbryUri.UriModifier.parse("#", "1");
|
||||||
|
LbryUri.UriModifier secondaryMod = LbryUri.UriModifier.parse("#", "2");
|
||||||
|
expected.setChannelClaimId(primaryMod.getClaimId());
|
||||||
|
expected.setStreamClaimId(secondaryMod.getClaimId());
|
||||||
|
} catch (LbryUriException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals(expected, obtained);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void lbryToTvString() {
|
public void lbryToTvString() {
|
||||||
LbryUri obtained = new LbryUri();
|
LbryUri obtained = new LbryUri();
|
||||||
|
|
Loading…
Reference in a new issue