Skip to content

Negative indexes out of range #31

@cragravorem

Description

@cragravorem

jsonpath2 version

0.4.0

Platform Details

sys.platform, sys.version == ('win32', '3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 21:26:53) [MSC v.1916 32 bit (Intel)]')

Scenario:

Using negative ranges to query last N elements of an array you get more elements than in the array itself if the array's length is smaller than N.

Steps to Reproduce:

Query $[-10:] on a [1, 2, 3] array

Expected Result:

>>> [m.current_value for m in Path.parse_str('$[-10:]').match([1, 2, 3])]
[1, 2, 3]

>>> [m.current_value for m in Path.parse_str('$[-10:]').match([1, 2, 3, 4, 5, 6, 7, 8])]
[1, 2, 3, 4, 5, 6, 7, 8]

Actual Result:

>>> [m.current_value for m in Path.parse_str('$[-10:]').match([1, 2, 3])]
[1, 2, 3, 1, 2, 3]

>>> [m.current_value for m in Path.parse_str('$[-10:]').match([1, 2, 3, 4, 5, 6, 7, 8])]
[7, 8, 1, 2, 3, 4, 5, 6, 7, 8]

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