Decode and encode urls with non-authorized characters #1174
2 changed files with 48 additions and 3 deletions
|
@ -2,6 +2,7 @@ package io.lbry.browser.utils;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
|
import java.net.URLEncoder;
|
||||||
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;
|
||||||
|
@ -199,7 +200,18 @@ public class LbryUri {
|
||||||
if (channelName != null) {
|
if (channelName != null) {
|
||||||
formattedChannelName = channelName.startsWith("@") ? channelName : String.format("@%s", channelName);
|
formattedChannelName = channelName.startsWith("@") ? channelName : String.format("@%s", channelName);
|
||||||
}
|
}
|
||||||
String primaryClaimName = claimName;
|
String primaryClaimName = null;
|
||||||
|
|
||||||
|
if (protocol.equals(LBRY_TV_BASE_URL) && Helper.isNullOrEmpty(formattedChannelName)) {
|
||||||
|
try {
|
||||||
|
primaryClaimName = URLEncoder.encode(claimName, UTF_8);
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
primaryClaimName = claimName;
|
||||||
|
}
|
||||||
|
|
||||||
if (Helper.isNullOrEmpty(primaryClaimName)) {
|
if (Helper.isNullOrEmpty(primaryClaimName)) {
|
||||||
primaryClaimName = contentName;
|
primaryClaimName = contentName;
|
||||||
}
|
}
|
||||||
|
@ -229,8 +241,16 @@ public class LbryUri {
|
||||||
secondaryClaimName = contentName;
|
secondaryClaimName = contentName;
|
||||||
}
|
}
|
||||||
if (Helper.isNullOrEmpty(secondaryClaimName)) {
|
if (Helper.isNullOrEmpty(secondaryClaimName)) {
|
||||||
|
if (protocol.equals(LBRY_TV_BASE_URL)) {
|
||||||
|
try {
|
||||||
|
secondaryClaimName = !Helper.isNullOrEmpty(formattedChannelName) ? URLEncoder.encode(streamName, UTF_8) : null;
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
secondaryClaimName = !Helper.isNullOrEmpty(formattedChannelName) ? streamName : null;
|
secondaryClaimName = !Helper.isNullOrEmpty(formattedChannelName) ? streamName : null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
String secondaryClaimId = !Helper.isNullOrEmpty(secondaryClaimName) ? streamClaimId : null;
|
String secondaryClaimId = !Helper.isNullOrEmpty(secondaryClaimName) ? streamClaimId : null;
|
||||||
|
|
||||||
if (!Helper.isNullOrEmpty(primaryClaimId)) {
|
if (!Helper.isNullOrEmpty(primaryClaimId)) {
|
||||||
|
|
|
@ -137,7 +137,6 @@ public class LbryUriTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEquals(expected, obtained);
|
assertEquals(expected, obtained);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -153,6 +152,32 @@ public class LbryUriTest {
|
||||||
assertEquals("https://lbry.tv/@lbry:3f/lbryturns4:6", obtained.toTvString());
|
assertEquals("https://lbry.tv/@lbry:3f/lbryturns4:6", obtained.toTvString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void lbryToTvStringWithEncodedChars() {
|
||||||
|
LbryUri obtained = new LbryUri();
|
||||||
|
|
||||||
|
try {
|
||||||
|
obtained = LbryUri.parse("lbry://La-Peur,-Nos-Attentats,-c'est-VOTRE-Sécurité!-Les-Guignols#6",false);
|
||||||
|
} catch (LbryUriException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals("https://lbry.tv/La-Peur%2C-Nos-Attentats%2C-c%27est-VOTRE-Se%CC%81curite%CC%81%21-Les-Guignols:6", obtained.toTvString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void lbryToTvStringWithChannelAndEncodedChars() {
|
||||||
|
LbryUri obtained = new LbryUri();
|
||||||
|
|
||||||
|
try {
|
||||||
|
obtained = LbryUri.parse("lbry://@test#1/La-Peur,-Nos-Attentats,-c'est-VOTRE-Sécurité!-Les-Guignols#6",false);
|
||||||
|
} catch (LbryUriException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals("https://lbry.tv/@test:1/La-Peur%2C-Nos-Attentats%2C-c%27est-VOTRE-Se%CC%81curite%CC%81%21-Les-Guignols:6", obtained.toTvString());
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private LbryUri sinthesizeExpected() {
|
private LbryUri sinthesizeExpected() {
|
||||||
LbryUri expectedForChannel = new LbryUri();
|
LbryUri expectedForChannel = new LbryUri();
|
||||||
|
|
Loading…
Reference in a new issue