Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-114219

NBT integer array regex matches non integer arrays

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Minecraft 17w16a
    • Minecraft 1.11.2, Minecraft 17w13a, Minecraft 17w13b, Minecraft 17w14a, Minecraft 17w15a
    • Confirmed

      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 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*,?\]
      

            Unassigned Unassigned
            marcono1234 Marcono1234
            Votes:
            4 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:
              CHK: