Skip to content

Commit

Permalink
move disallowed characters RegEx to config
Browse files Browse the repository at this point in the history
  • Loading branch information
zefir-git committed Jun 13, 2024
1 parent 0cb8bf7 commit 66dc461
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/main/java/pro/cloudnode/smp/bankaccounts/BankConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Optional;
import java.util.Set;
import java.util.TimeZone;
import java.util.regex.Pattern;

public final class BankConfig {
public @NotNull FileConfiguration config;
Expand Down Expand Up @@ -422,6 +423,11 @@ public int invoicePerPage() {
return config.getInt("invoice.per-page");
}

// disallowed-regex
public @NotNull Pattern disallowedRegex() {
return Pattern.compile(Objects.requireNonNull(config.getString("disallowed-regex")));
}

// messages.command-usage
public @NotNull Component messagesCommandUsage(final @NotNull String command, final @NotNull String arguments) {
return MiniMessage.miniMessage().deserialize(
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/pro/cloudnode/smp/bankaccounts/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ public final boolean onCommand(final @NotNull CommandSender sender, final @NotNu
.filter(codePoint -> codePoint > 0xFFFF)
.mapToObj(codePoint -> new String(Character.toChars(codePoint)))
.collect(Collectors.toSet());
final @NotNull Matcher matcher = Pattern.compile("[<>\\x00-\\x08\\x0B-\\x1F\\x7F-\\x9F\\u2400-\\u2421\\u200B-\\u200D\\uFEFF\\uD800-\\uDB7F\\uDFFF]").matcher(input);
final @NotNull Matcher matcher = BankAccounts.getInstance().config().disallowedRegex().matcher(input);
while (matcher.find()) chars.add(matcher.group());
if (input.contains("<")) chars.add("<");
if (input.contains(">")) chars.add(">");
return chars;
}
}
6 changes: 6 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,12 @@ invoice:
# Number of invoices to return per page
per-page: 10

# Advanced: do not edit unless you have good understanding of RegEx
# Regular expression for disallowed characters user-provided text inputs
# e.g. account name, transaction description, POS description, invoice description
# Note: additionally <> is always disallowed to prevent the use of placeholders or formatting.
disallowed-regex: [\x00-\x08\x0B-\x1F\x7F-\x9F\u2400-\u2421\u200B-\u200D\uFEFF\uD800-\uDB7F\uDFFF]

# Messages
messages:
# Command usage message
Expand Down

0 comments on commit 66dc461

Please sign in to comment.