From 8a6ca4f67bff27dfbf2556069109b557a7a200c0 Mon Sep 17 00:00:00 2001 From: zml Date: Wed, 23 Mar 2022 15:06:06 -0700 Subject: [PATCH] common: Should we sanitize enum names? This resolves issues where mods add enum entries with names that are not valid resource locations --- .../common/registry/VanillaRegistryLoader.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/spongepowered/common/registry/VanillaRegistryLoader.java b/src/main/java/org/spongepowered/common/registry/VanillaRegistryLoader.java index fc3abb1c7e5..56afa69c2ac 100644 --- a/src/main/java/org/spongepowered/common/registry/VanillaRegistryLoader.java +++ b/src/main/java/org/spongepowered/common/registry/VanillaRegistryLoader.java @@ -207,7 +207,7 @@ private void loadEnumRegistries() { this.knownName(RegistryTypes.BANNER_PATTERN_SHAPE, BannerPattern.values(), b -> ((BannerPatternAccessor) (Object) b).accessor$filename()); this.automaticName(RegistryTypes.TROPICAL_FISH_SHAPE, TropicalFish.Pattern.values()); this.automaticName(RegistryTypes.HEIGHT_TYPE, Heightmap.Types.values()); - this.knownName(RegistryTypes.ENTITY_CATEGORY, MobCategory.values(), MobCategory::getName); + this.knownName(RegistryTypes.ENTITY_CATEGORY, MobCategory.values(), VanillaRegistryLoader.sanitizedName(MobCategory::getName)); } private static RegistryLoader criterion() { @@ -293,7 +293,7 @@ private static RegistryLoader> trigger() { @SuppressWarnings("UnusedReturnValue") private > Registry automaticName(final RegistryType type, final I[] values) { - return this.naming(type, values, value -> value.name().toLowerCase(Locale.ROOT)); + return this.naming(type, values, VanillaRegistryLoader.sanitizedName(Enum::name)); } @SuppressWarnings("UnusedReturnValue") @@ -363,4 +363,8 @@ private Registry naming(final RegistryType type, final int values, private interface Manual { void put(final I value, final String key); } + + private static Function sanitizedName(final Function original) { + return original.andThen(s -> s.toLowerCase(Locale.ROOT)); + } }