Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

text-minimessage: Validate tag names in resolver builder #771

Merged
merged 1 commit into from May 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -30,6 +30,7 @@
import java.util.List;
import java.util.Map;
import java.util.stream.Collector;
import net.kyori.adventure.text.minimessage.internal.TagInternals;
import net.kyori.adventure.text.minimessage.tag.Tag;
import org.jetbrains.annotations.NotNull;

Expand All @@ -48,8 +49,9 @@ final class TagResolverBuilderImpl implements TagResolver.Builder {

@Override
public TagResolver.@NotNull Builder tag(final @NotNull String name, final @NotNull Tag tag) {
TagInternals.assertValidTagName(requireNonNull(name, "name"));
this.replacements.put(
requireNonNull(name, "name"),
name,
requireNonNull(tag, "tag")
);
return this;
Expand Down
Expand Up @@ -128,6 +128,12 @@ void testInvalidTagName() {
assertThrows(IllegalArgumentException.class, () -> TagResolver.resolver("#test#", Tag.preProcessParsed("something")));
}

// https://github.com/KyoriPowered/adventure/issues/763
@Test
void testBuilderValidatesTagName() {
assertThrows(IllegalArgumentException.class, () -> TagResolver.builder().tag("INVALID#NAME", Tag.preProcessParsed("something")));
}

@Test
void testValidTagName() {
assertDoesNotThrow(() -> TagResolver.resolver("valid_-name0909", Tag.preProcessParsed("something")));
Expand Down