fix opening matrix.to link under support button by escaping

This commit is contained in:
woodser 2025-07-05 10:56:02 -04:00 committed by GitHub
parent 19d4df8b2e
commit 93f6337e6a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -124,6 +124,8 @@ import java.io.OutputStreamWriter;
import java.math.BigInteger;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
@ -721,13 +723,26 @@ public class GUIUtil {
private static void doOpenWebPage(String target) {
try {
Utilities.openURI(new URI(target));
Utilities.openURI(safeParse(target));
} catch (Exception e) {
e.printStackTrace();
log.error(e.getMessage());
}
}
private static URI safeParse(String url) throws URISyntaxException {
int hashIndex = url.indexOf('#');
if (hashIndex >= 0 && hashIndex < url.length() - 1) {
String base = url.substring(0, hashIndex);
String fragment = url.substring(hashIndex + 1);
String encodedFragment = URLEncoder.encode(fragment, StandardCharsets.UTF_8);
return new URI(base + "#" + encodedFragment);
}
return new URI(url); // no fragment
}
public static String getPercentageOfTradeAmount(BigInteger fee, BigInteger tradeAmount) {
String result = " (" + getPercentage(fee, tradeAmount) +
" " + Res.get("guiUtil.ofTradeAmount") + ")";