Skip to content

Commit

Permalink
text-minimessage: Validate tag names in resolver builder
Browse files Browse the repository at this point in the history
  • Loading branch information
zml2008 committed May 31, 2022
1 parent 1b18515 commit 7085b78
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 7085b78

Please sign in to comment.