Skip to content

Replace mod exclusion from contains(...) to matches(...), so we can use regex

Currently we are using

if (modsInModpack.removeIf(n -> (n.contains(userSpecifiedClientMods.get(i))))) {
    LOG.debug("Removed user-specified mod from mods list as per input: " + userSpecifiedClientMods.get(i));
}

This can lead to false positives the more entries the fallback list or clientside-only modslist has. A way to combat this would be to use regex. Using regex would immensly increase the complexity and possibly even the time it takes to determine whether a mod should be excluded, but it would be the most secure way of specifying a mod without running the risk of accidentally excluding a needed mod. TL;DR: Regex = no false positives

Proposal:

if (modsInModpack.removeIf(n -> (n.matches(userSpecifiedClientMods.get(i))))) {
    LOG.debug("Removed user-specified mod from mods list as per input: " + userSpecifiedClientMods.get(i));
}

Another solution would be to give users the ability to choose between regex, contains and startsWith

switch (ExclusionMode) {

    case CONTAINS:
        if (modsInModpack.removeIf(n -> (n.contains(userSpecifiedClientMods.get(i))))) {
            LOG.debug("Removed user-specified mod from mods list as per input: " + userSpecifiedClientMods.get(i));
        }
        break;

    case MATCHES:
        if (modsInModpack.removeIf(n -> (n.matches(userSpecifiedClientMods.get(i))))) {
            LOG.debug("Removed user-specified mod from mods list as per input: " + userSpecifiedClientMods.get(i));
        }
        break;

    case STARTSWITH:
        if (modsInModpack.removeIf(n -> (n.startsWith(userSpecifiedClientMods.get(i))))) {
            LOG.debug("Removed user-specified mod from mods list as per input: " + userSpecifiedClientMods.get(i));
        }
        break;
}