mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-24 11:38:40 +01:00
Don't allow empty context keys/values (#688)
This commit is contained in:
parent
8a374aed04
commit
ed223f0e4e
@ -122,11 +122,33 @@ abstract class AbstractContextSet implements ContextSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static String sanitizeKey(String key) {
|
static String sanitizeKey(String key) {
|
||||||
return Objects.requireNonNull(key, "key is null").toLowerCase().intern();
|
Objects.requireNonNull(key, "key is null");
|
||||||
|
if (stringIsEmpty(key)) {
|
||||||
|
throw new IllegalArgumentException("key is (effectively) empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
return key.toLowerCase().intern();
|
||||||
}
|
}
|
||||||
|
|
||||||
static String sanitizeValue(String value) {
|
static String sanitizeValue(String value) {
|
||||||
return Objects.requireNonNull(value, "value is null").intern();
|
Objects.requireNonNull(value, "value is null");
|
||||||
|
if (stringIsEmpty(value)) {
|
||||||
|
throw new IllegalArgumentException("value is (effectively) empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
return value.intern();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean stringIsEmpty(String s) {
|
||||||
|
if (s.isEmpty()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
for (char c : s.toCharArray()) {
|
||||||
|
if (c != ' ') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,9 @@ import javax.annotation.Nonnull;
|
|||||||
* {@link String#toLowerCase() lowercase} by all implementations.
|
* {@link String#toLowerCase() lowercase} by all implementations.
|
||||||
* Values however are case-sensitive.</p>
|
* Values however are case-sensitive.</p>
|
||||||
*
|
*
|
||||||
* <p>Context keys and values may not be null.</p>
|
* <p>Context keys and values may not be null or empty. A key/value will be
|
||||||
|
* deemed empty if it's length is zero, or if it consists of only space
|
||||||
|
* characters.</p>
|
||||||
*
|
*
|
||||||
* <p>Two default ContextSet implementations are provided.
|
* <p>Two default ContextSet implementations are provided.
|
||||||
* {@link MutableContextSet} allows the addition and removal of context keys
|
* {@link MutableContextSet} allows the addition and removal of context keys
|
||||||
|
@ -134,12 +134,12 @@ public class ArgumentUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String key = pair.substring(0, index);
|
String key = pair.substring(0, index);
|
||||||
if (key.equals("")) {
|
if (key.equals("") || key.trim().isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String value = pair.substring(index + 1);
|
String value = pair.substring(index + 1);
|
||||||
if (value.equals("")) {
|
if (value.equals("") || value.trim().isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user