diff --git a/app/src/main/java/io/github/trojan_gfw/igniter/TrojanHelper.java b/app/src/main/java/io/github/trojan_gfw/igniter/TrojanHelper.java index 33765d8a..5690716a 100644 --- a/app/src/main/java/io/github/trojan_gfw/igniter/TrojanHelper.java +++ b/app/src/main/java/io/github/trojan_gfw/igniter/TrojanHelper.java @@ -186,4 +186,21 @@ public static void ShowConfig(String trojanConfigPath) { e.printStackTrace(); } } + + public static String RemoveAllEmoji(String str) { + /* + * [\\p{L}\\p{M}\\p{N}\\p{P}\\p{Z}\\p{Cf}\\p{Cs}\\s] is a range representing + * all numeric (\\p{N}), letter (\\p{L}), mark (\\p{M}), punctuation (\\p{P}), + * whitespace/separator (\\p{Z}), other formatting (\\p{Cf}) and other characters + * above U+FFFF in Unicode (\\p{Cs}), and newline (\\s) characters. + * \\p{L} specifically includes the characters from other alphabets + * such as Cyrillic, Latin, Kanji, etc. + */ + if (str == null || str.length() <= 0) { + // do nothing + return str; + } + String characterFilter = "[^\\p{L}\\p{M}\\p{N}\\p{P}\\p{Z}\\p{Cf}\\p{Cs}\\s]"; + return str.replaceAll(characterFilter,""); + } } diff --git a/app/src/main/java/io/github/trojan_gfw/igniter/servers/data/ServerListDataManager.java b/app/src/main/java/io/github/trojan_gfw/igniter/servers/data/ServerListDataManager.java index 287e8329..17b9f796 100644 --- a/app/src/main/java/io/github/trojan_gfw/igniter/servers/data/ServerListDataManager.java +++ b/app/src/main/java/io/github/trojan_gfw/igniter/servers/data/ServerListDataManager.java @@ -190,7 +190,8 @@ private void parseAndSaveSubscribeServers(@NonNull String configLines) { idxOfLineEnd = i; if (idxOfSharp != -1) { String trojanUrl = configLines.substring(idxOfLineStart, idxOfSharp); - String remark = configLines.substring(idxOfSharp + 1, idxOfLineEnd).trim(); + String rawRemark = configLines.substring(idxOfSharp + 1, idxOfLineEnd).trim(); + String remark = TrojanHelper.RemoveAllEmoji(rawRemark); TrojanURLParseResult parseResult = TrojanURLHelper.ParseTrojanURL(trojanUrl); if (parseResult != null) { TrojanConfig newConfig = TrojanURLHelper.CombineTrojanURLParseResultToTrojanConfig(parseResult, Globals.getTrojanConfigInstance()); @@ -294,7 +295,9 @@ private List parseTrojanConfigsFromFileContent(String fileContent) continue; } TrojanConfig tmp = new TrojanConfig(); - tmp.setRemoteServerRemark(config.optString(ConfigFileConstants.REMARKS, ConfigFileConstants.EMPTY_STRING)); + String rawRemoteServerRemark = config.optString(ConfigFileConstants.REMARKS, ConfigFileConstants.EMPTY_STRING); + String remoteServerRemark = TrojanHelper.RemoveAllEmoji(rawRemoteServerRemark); + tmp.setRemoteServerRemark(remoteServerRemark); tmp.setRemoteAddr(remoteAddr); tmp.setRemotePort(config.optInt(ConfigFileConstants.SERVER_PORT)); tmp.setSNI(config.optString(ConfigFileConstants.SNI, ConfigFileConstants.EMPTY_STRING));