Mojira Archive
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 [Mod] Pokechu22
regexr link

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

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

Fixed

Marcono1234

2017-02-26, 11:41 PM

2017-04-20, 05:22 PM

2017-04-20, 05:22 PM

4

5

Confirmed

NBT, integer, match, nbt, pattern

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

Minecraft 17w16a