Skip to content

Test uses negative array indexes #47

Open
@pbrisbin

Description

@pbrisbin

Correct me if I'm wrong, but in the JSON Pointer spec, I don't think it is possible to even parse necessary to represent a negative array index:

   o  If the currently referenced value is a JSON array, the reference
      token MUST contain either:

      *  characters comprised of digits (see ABNF below; note that
         leading zeros are not allowed) that represent an unsigned
         base-10 integer value, making the new referenced value the
         array element with the zero-based index identified by the
         token, or

      *  exactly the single character "-", making the new referenced
         value the (nonexistent) member after the last array element.

   The ABNF syntax for array indices is:

   array-index = %x30 / ( %x31-39 *(%x30-39) )
                 ; "0", or digits without a leading "0"

Therefore, I think this is a misleading test:

  {
    "doc": {
      "bar": [
        1,
        2
      ]
    },
    "patch": [
      {
        "op": "add",
        "path": "/bar/-1",
        "value": "5"
      }
    ],
    "error": "Out of bounds (lower)"
  }

I think it would be reasonable for an implementation to a) not parse negative numbers in reference tokens and b) never check for lower-bounds errors (since negative indexes are simply not possible). Doing that seems to result in path being reported as invalid because "-1" is treated as an object key that is inappropriate to reference an array value, which I think is more in the spirit of the spec.

The path is reported invalid either way, so the test is still valuable in that it tests for some error condition, but it currently tests for an error due to bounds specifically, so I bumped on it when trying to make my test suite a little more strict.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions