fix: use correct regex to check for legal strings
This commit is contained in:
parent
5cd0d91dd6
commit
b382bdf3a5
|
@ -29,11 +29,11 @@
|
||||||
thisIsCool: true,
|
thisIsCool: true,
|
||||||
numberInSub: 15,
|
numberInSub: 15,
|
||||||
enumInSub: [
|
enumInSub: [
|
||||||
"zthis is default",
|
"zthisIsDefault",
|
||||||
"yay1",
|
"yay1",
|
||||||
"yay2",
|
"yay2",
|
||||||
"yay3",
|
"yay3",
|
||||||
"athis is last"
|
"athisIsLast"
|
||||||
],
|
],
|
||||||
sliderTest: {
|
sliderTest: {
|
||||||
min: 15,
|
min: 15,
|
||||||
|
|
|
@ -8,8 +8,7 @@ import io.gitlab.jfronny.muscript.StandardLib;
|
||||||
import io.gitlab.jfronny.muscript.ast.*;
|
import io.gitlab.jfronny.muscript.ast.*;
|
||||||
import io.gitlab.jfronny.muscript.data.Scope;
|
import io.gitlab.jfronny.muscript.data.Scope;
|
||||||
import io.gitlab.jfronny.muscript.data.dynamic.additional.DFinal;
|
import io.gitlab.jfronny.muscript.data.dynamic.additional.DFinal;
|
||||||
import io.gitlab.jfronny.respackopts.filters.DirFilterEvents;
|
import io.gitlab.jfronny.respackopts.filters.*;
|
||||||
import io.gitlab.jfronny.respackopts.filters.FileFilterEvents;
|
|
||||||
import io.gitlab.jfronny.respackopts.gson.*;
|
import io.gitlab.jfronny.respackopts.gson.*;
|
||||||
import io.gitlab.jfronny.respackopts.gson.entry.*;
|
import io.gitlab.jfronny.respackopts.gson.entry.*;
|
||||||
import io.gitlab.jfronny.respackopts.integration.SaveHook;
|
import io.gitlab.jfronny.respackopts.integration.SaveHook;
|
||||||
|
@ -76,8 +75,10 @@ public class Respackopts implements ModInitializer, SaveHook {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
|
if (RespackoptsConfig.ioLogs) DebugEvents.preInit();
|
||||||
DirFilterEvents.init();
|
DirFilterEvents.init();
|
||||||
FileFilterEvents.init();
|
FileFilterEvents.init();
|
||||||
|
if (RespackoptsConfig.ioLogs) DebugEvents.postInit();
|
||||||
ServerInstanceHolder.init();
|
ServerInstanceHolder.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,11 +101,12 @@ public class Respackopts implements ModInitializer, SaveHook {
|
||||||
// [\\s_] = whitespace or underscores
|
// [\\s_] = whitespace or underscores
|
||||||
// | = or
|
// | = or
|
||||||
// [^a-zA-Z_] = not character or underscore
|
// [^a-zA-Z_] = not character or underscore
|
||||||
private static final Pattern UNSUPPORTED = Pattern.compile("[^a-zA-Z_]|^[\\s_]*|[\\s_]*$");
|
private static final Pattern UNSUPPORTED = Pattern.compile("\\W+|^\\d+");
|
||||||
|
private static final Pattern SANITIZABLE = Pattern.compile(UNSUPPORTED + "|^_+|_+$");
|
||||||
|
|
||||||
public static String sanitizeString(String s) {
|
public static String sanitizeString(String s) {
|
||||||
// This trims whitespace/underscores and removes non-alphabetical or underscore characters
|
// This trims whitespace/underscores and removes non-alphabetical or underscore characters
|
||||||
return UNSUPPORTED.matcher(s).replaceAll("");
|
return SANITIZABLE.matcher(s).replaceAll("");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isLegal(String s) {
|
public static boolean isLegal(String s) {
|
||||||
|
|
|
@ -11,6 +11,7 @@ import java.util.List;
|
||||||
public class RespackoptsConfig implements JfCustomConfig {
|
public class RespackoptsConfig implements JfCustomConfig {
|
||||||
public static boolean debugCommands = false;
|
public static boolean debugCommands = false;
|
||||||
public static boolean debugLogs = false;
|
public static boolean debugLogs = false;
|
||||||
|
public static boolean ioLogs = false;
|
||||||
public static boolean dashloaderCompat = true;
|
public static boolean dashloaderCompat = true;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -19,6 +20,7 @@ public class RespackoptsConfig implements JfCustomConfig {
|
||||||
Respackopts.CONFIG = dsl.register(builder -> builder
|
Respackopts.CONFIG = dsl.register(builder -> builder
|
||||||
.value("debugCommands", debugCommands, () -> debugCommands, v -> debugCommands = v)
|
.value("debugCommands", debugCommands, () -> debugCommands, v -> debugCommands = v)
|
||||||
.value("debugLogs", debugLogs, () -> debugLogs, v -> debugLogs = v)
|
.value("debugLogs", debugLogs, () -> debugLogs, v -> debugLogs = v)
|
||||||
|
.value("ioLogs", ioLogs, () -> ioLogs, v -> ioLogs = v)
|
||||||
.value("dashloaderCompat", dashloaderCompat, () -> dashloaderCompat, v -> dashloaderCompat = v)
|
.value("dashloaderCompat", dashloaderCompat, () -> dashloaderCompat, v -> dashloaderCompat = v)
|
||||||
.setPath(Respackopts.FALLBACK_CONF_DIR.resolve("_respackopts.conf"))
|
.setPath(Respackopts.FALLBACK_CONF_DIR.resolve("_respackopts.conf"))
|
||||||
.referenceConfig(() -> {
|
.referenceConfig(() -> {
|
||||||
|
|
|
@ -12,8 +12,11 @@ import java.util.function.Supplier;
|
||||||
public enum DebugEvents implements UserResourceEvents.FindResource, UserResourceEvents.ParseMetadata, UserResourceEvents.Open, UserResourceEvents.OpenRoot {
|
public enum DebugEvents implements UserResourceEvents.FindResource, UserResourceEvents.ParseMetadata, UserResourceEvents.Open, UserResourceEvents.OpenRoot {
|
||||||
INSTANCE;
|
INSTANCE;
|
||||||
|
|
||||||
public static void init() {
|
public static void preInit() {
|
||||||
UserResourceEvents.FIND_RESOURCE.register(INSTANCE);
|
UserResourceEvents.FIND_RESOURCE.register(INSTANCE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void postInit() {
|
||||||
UserResourceEvents.PARSE_METADATA.register(INSTANCE);
|
UserResourceEvents.PARSE_METADATA.register(INSTANCE);
|
||||||
UserResourceEvents.OPEN.register(INSTANCE);
|
UserResourceEvents.OPEN.register(INSTANCE);
|
||||||
UserResourceEvents.OPEN_ROOT.register(INSTANCE);
|
UserResourceEvents.OPEN_ROOT.register(INSTANCE);
|
||||||
|
|
|
@ -86,7 +86,7 @@ public class ResourcePackManagerMixin {
|
||||||
PackMeta conf = Respackopts.GSON.fromJson(isr, PackMeta.class);
|
PackMeta conf = Respackopts.GSON.fromJson(isr, PackMeta.class);
|
||||||
if (!Respackopts.isLegal(conf.id)) {
|
if (!Respackopts.isLegal(conf.id)) {
|
||||||
if (conf.version >= 10) {
|
if (conf.version >= 10) {
|
||||||
Respackopts.LOGGER.error(displayName + " was not loaded as it uses an unsupported pack id");
|
Respackopts.LOGGER.error(displayName + " was not loaded as it uses an unsupported pack id: " + conf.id);
|
||||||
return null;
|
return null;
|
||||||
} else conf.id = Respackopts.sanitizeString(conf.id);
|
} else conf.id = Respackopts.sanitizeString(conf.id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
"respackopts.jfconfig.title": "ResPackOpts",
|
"respackopts.jfconfig.title": "ResPackOpts",
|
||||||
"respackopts.jfconfig.debugCommands": "Debug Commands",
|
"respackopts.jfconfig.debugCommands": "Debug Commands",
|
||||||
"respackopts.jfconfig.debugLogs": "Debug Logs",
|
"respackopts.jfconfig.debugLogs": "Debug Logs",
|
||||||
|
"respackopts.jfconfig.ioLogs": "IO Logs",
|
||||||
|
"respackopts.jfconfig.ioLogs.tooltip": "Log every resource access. WARNING: This WILL result in giant log files! (requires restart)",
|
||||||
"respackopts.jfconfig.dashloaderCompat": "Dashloader compatibility",
|
"respackopts.jfconfig.dashloaderCompat": "Dashloader compatibility",
|
||||||
"respackopts.invalid": "Invalid value",
|
"respackopts.invalid": "Invalid value",
|
||||||
"respackopts.dumpSucceeded": "Successfully dumped the resource to %s",
|
"respackopts.dumpSucceeded": "Successfully dumped the resource to %s",
|
||||||
|
|
Loading…
Reference in New Issue