mojira.dev
MC-174587

Greedy strings cannot contain trailing spaces in a function

The bug

Because commands in a function are trimmed by java.lang.String#trim, greedy strings cannot contain trailing spaces (U+0000 .. U+0020) in a function.

Affected commands

  • /advancement grant <targets> only <advancement> <criterion>

  • /advancement revoke <targets> only <advancement> <criterion>

  • /say <message>

How to reproduce

  1. Install the datapack in Attachments.

/function mc-174587:test

→ ❌ revoked, the criterion "criterion with a trailing space " is not granted correctly.

  • mc-174587/advancement/test.json

    {
        "criteria": {
            "criterion with a trailing space ": {
                "trigger": "minecraft:impossible"
            }
        }
    }
  • mc-174587/functions/test.mcfunction

    advancement grant @s only mc-174587:test criterion with a trailing space 
    execute if entity @s[advancements={mc-174587:test=true}] run say granted
    execute if entity @s[advancements={mc-174587:test=false}] run say revoked

Linked issues

Attachments

Comments 4

Partially fixed in 23w31a, thanks to macros. We can now generate commands that start and/or end with spaces as follows:

  1. Load the following macro

mc-174587:macro

$advancement grant @s only mc-174587:test $(criterion)
execute if entity @s[advancements={mc-174587:test=true}] run say granted
execute if entity @s[advancements={mc-174587:test=false}] run say revoked
  1. Run the following command

    function mc-174587:macro {criterion: "criterion with a trailing space "}

    → ✔ granted

Considering the overhead of macros, I would also like this to be achievable with just a function though.

Fixed in 23w31a. I have just noticed that we can include trailing spaces in a function by writing spaces followed by \ and leaving the next line empty as follows:

advancement grant @s only mc-174587:test criterion with a trailing space \

execute if entity @s[advancements={mc-174587:test=true}] run say granted
execute if entity @s[advancements={mc-174587:test=false}] run say revoked

→ ✔ granted

That's not fixed, that's a workaround; lines still cannot end with spaces. Your function's line ends with a "continue on next line", not a trailing space.

Yes, indeed, this is just making it non-trailing by guarding the trailing spaces with a \. It doesn't seem right that trailing trim and greedy strings coexist, but when such a purely syntactic workaround emerges, this issue might be considered as a feature request, like MC-264999. I'd like to leave the decision to the moderators and developers.

intsuc

(Unassigned)

Confirmed

Commands

/advancement, /say, function

1.15.2, 20w11a, 20w12a, 20w14a, 20w16a, ..., 23w18a, 1.20.1, 1.20.2, 23w42a, 24w04a

Retrieved