mojira.dev
MC-114219

NBT integer array regex matches non integer arrays

The bug

The regex for integer arrays to distinct them from lists is

\[[-+\d|,\s]+\]

This matches int array items things like

+++
---
+-+-
1+1
1 \t\n\x0B\f\r4

which cannot be parsed as integers.

Note: It might be good if the string would be parsed as list if it could not be parsed as integer array, because a NBT list would be more obvious than a NBT string given that it matched the list requirements in the first place.

How to reproduce

  1. Use the following command

    /give @p stone 1 0 {IntArrayTest:[+++,---,+-+-]}
  2. Throw the item on the ground and inspect its NBT data

    /entitydata @e[type=item,c=1] {}

    → You will see that the tag IntArrayTest is a String (IntArrayTest:"[+++,---,+-+-]") instead of a list (IntArrayTest:["+++","---","+-+-"]), which means it matched the integer array pattern but could not be converted to an integer array

Suggested regex

The suggested regex could for example be

\[(?:[+-]?\d+\s*,\s*)*(?:[+-]?\d+)\]

by @unknown
regexr link

or maybe with additional whitespaces in case somebody wants to parse a pretty printed integer array:

\[\s*(?:[+-]?\d+\s*,\s*)*[+-]?\d+\s*,?\]

Linked issues

Comments 0

No comments.

marcono1234

(Unassigned)

Confirmed

NBT, integer, match, nbt, pattern

Minecraft 1.11.2, Minecraft 17w13a, Minecraft 17w13b, Minecraft 17w14a, Minecraft 17w15a

Minecraft 17w16a

Retrieved