Ensure meta keys are always lowercase, and fix 'similar' comparison case sensitivity (#2760)

This commit is contained in:
Luck 2020-12-09 10:38:22 +00:00
parent 798a539024
commit 5fbb80f16a
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
3 changed files with 6 additions and 11 deletions

View File

@ -100,14 +100,13 @@ public enum StandardComparison implements Comparison {
} }
static Pattern compilePatternForLikeSyntax(String expression) { static Pattern compilePatternForLikeSyntax(String expression) {
expression = expression.toLowerCase();
expression = expression.replace(".", "\\."); expression = expression.replace(".", "\\.");
// convert from SQL LIKE syntax to regex // convert from SQL LIKE syntax to regex
expression = expression.replace(WILDCARD_ONE, "."); expression = expression.replace(WILDCARD_ONE, ".");
expression = expression.replace(WILDCARD, ".*"); expression = expression.replace(WILDCARD, ".*");
return Pattern.compile(expression); return Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
} }
} }

View File

@ -27,12 +27,10 @@ package me.lucko.luckperms.common.node.types;
import me.lucko.luckperms.common.node.AbstractNode; import me.lucko.luckperms.common.node.AbstractNode;
import me.lucko.luckperms.common.node.AbstractNodeBuilder; import me.lucko.luckperms.common.node.AbstractNodeBuilder;
import net.luckperms.api.context.ImmutableContextSet; import net.luckperms.api.context.ImmutableContextSet;
import net.luckperms.api.model.group.Group; import net.luckperms.api.model.group.Group;
import net.luckperms.api.node.metadata.NodeMetadataKey; import net.luckperms.api.node.metadata.NodeMetadataKey;
import net.luckperms.api.node.types.InheritanceNode; import net.luckperms.api.node.types.InheritanceNode;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
@ -44,7 +42,7 @@ public class Inheritance extends AbstractNode<InheritanceNode, InheritanceNode.B
private static final String NODE_MARKER = NODE_KEY + "."; private static final String NODE_MARKER = NODE_KEY + ".";
public static String key(String groupName) { public static String key(String groupName) {
return NODE_MARKER + groupName; return NODE_MARKER + groupName.toLowerCase();
} }
public static Builder builder() { public static Builder builder() {
@ -59,7 +57,7 @@ public class Inheritance extends AbstractNode<InheritanceNode, InheritanceNode.B
public Inheritance(String groupName, boolean value, long expireAt, ImmutableContextSet contexts, Map<NodeMetadataKey<?>, Object> metadata) { public Inheritance(String groupName, boolean value, long expireAt, ImmutableContextSet contexts, Map<NodeMetadataKey<?>, Object> metadata) {
super(key(groupName), value, expireAt, contexts, metadata); super(key(groupName), value, expireAt, contexts, metadata);
this.groupName = groupName; this.groupName = groupName.toLowerCase();
} }
@Override @Override
@ -96,7 +94,7 @@ public class Inheritance extends AbstractNode<InheritanceNode, InheritanceNode.B
@Override @Override
public @NonNull Builder group(@NonNull String group) { public @NonNull Builder group(@NonNull String group) {
this.groupName = Objects.requireNonNull(group, "group").toLowerCase(); this.groupName = Objects.requireNonNull(group, "group");
return this; return this;
} }

View File

@ -28,11 +28,9 @@ package me.lucko.luckperms.common.node.types;
import me.lucko.luckperms.common.node.AbstractNode; import me.lucko.luckperms.common.node.AbstractNode;
import me.lucko.luckperms.common.node.AbstractNodeBuilder; import me.lucko.luckperms.common.node.AbstractNodeBuilder;
import me.lucko.luckperms.common.node.factory.Delimiters; import me.lucko.luckperms.common.node.factory.Delimiters;
import net.luckperms.api.context.ImmutableContextSet; import net.luckperms.api.context.ImmutableContextSet;
import net.luckperms.api.node.metadata.NodeMetadataKey; import net.luckperms.api.node.metadata.NodeMetadataKey;
import net.luckperms.api.node.types.MetaNode; import net.luckperms.api.node.types.MetaNode;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
@ -45,7 +43,7 @@ public class Meta extends AbstractNode<MetaNode, MetaNode.Builder> implements Me
private static final String NODE_MARKER = NODE_KEY + "."; private static final String NODE_MARKER = NODE_KEY + ".";
public static String key(String key, String value) { public static String key(String key, String value) {
return NODE_MARKER + Delimiters.escapeCharacters(key) + AbstractNode.NODE_SEPARATOR + Delimiters.escapeCharacters(value); return NODE_MARKER + Delimiters.escapeCharacters(key).toLowerCase() + AbstractNode.NODE_SEPARATOR + Delimiters.escapeCharacters(value);
} }
public static Builder builder() { public static Builder builder() {
@ -61,7 +59,7 @@ public class Meta extends AbstractNode<MetaNode, MetaNode.Builder> implements Me
public Meta(String metaKey, String metaValue, boolean value, long expireAt, ImmutableContextSet contexts, Map<NodeMetadataKey<?>, Object> metadata) { public Meta(String metaKey, String metaValue, boolean value, long expireAt, ImmutableContextSet contexts, Map<NodeMetadataKey<?>, Object> metadata) {
super(key(metaKey, metaValue), value, expireAt, contexts, metadata); super(key(metaKey, metaValue), value, expireAt, contexts, metadata);
this.metaKey = metaKey; this.metaKey = metaKey.toLowerCase();
this.metaValue = metaValue; this.metaValue = metaValue;
} }