Skip to content

Commit

Permalink
handle illegal server remark
Browse files Browse the repository at this point in the history
Signed-off-by: Syrone Wong <[email protected]>
  • Loading branch information
wongsyrone committed Nov 9, 2020
1 parent 2cdf5a0 commit 92731f1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
17 changes: 17 additions & 0 deletions app/src/main/java/io/github/trojan_gfw/igniter/TrojanHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,"");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -294,7 +295,9 @@ private List<TrojanConfig> 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));
Expand Down

0 comments on commit 92731f1

Please sign in to comment.