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

PreProcess tags do not handle arguments correctly #732

Closed
Joo200 opened this issue Mar 20, 2022 · 1 comment · Fixed by #735
Closed

PreProcess tags do not handle arguments correctly #732

Joo200 opened this issue Mar 20, 2022 · 1 comment · Fixed by #735

Comments

@Joo200
Copy link
Contributor

Joo200 commented Mar 20, 2022

Following unit test will fail:

  @Test
  void testNumberStuff() {
    final String input = "<test:'bla'> is a nice number";
    final Component expected = text("bla is a nice number");

    this.assertParsedEquals(
      expected,
      input,
      TagResolver.resolver("test", (argumentQueue, context) -> {
        if (argumentQueue.hasNext()) argumentQueue.pop();
        return Tag.preProcessParsed("bla");
      })
    );
  }

The Tag.preProcessParsed doesn't allow arguments. It will just remove the tag and doesn't insert the text.

I debugged MiniMessage and I was able to find:
https://github.com/KyoriPowered/adventure/blob/9403962bb1afbd3392b580654f68403dcd426f6a/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/internal/parser/match/StringResolvingMatchedTokenConsumer.java
String tag is "test:'bla', therefore TagInternals.sanitizeAndCheckValidTagName(tag) doesn't accept the tag as a valid tag and doesn't insert anything.

The arguments should be parsed and passed to the tagProvider.resolve call instead.

@Joo200
Copy link
Contributor Author

Joo200 commented Mar 20, 2022

Related to the sanitizing in StringResolvingMatchedTokenConsumer#L71 and following:

      final String cleanup = this.input.substring(start + 1, end - 1);
      final String tag = cleanup.substring(0, cleanup.indexOf(":"));

inserting this resolves the issue partially.
Then the tag will be resolved fine but no arg will be passed.

@kezz kezz changed the title MiniMessage: Tag with type PreProcess doesn't accept arguments PreProcess tags do not handle arguments correctly Mar 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants