julesfern / spahql

A query language for Javascript data. Extracted from Spah.
MIT License
325 stars 20 forks source link

Removal of Array Elements is in wrong order #13

Closed dokie closed 11 years ago

dokie commented 11 years ago

...nts in an array would leave indices unable to reference original array elements as they have been spliced

dokie commented 11 years ago

I found this using the following JSON

{
    "locationId": "80e8c7d6-c484-44fc-8219-d56ae4244ad4",
    "locationTypeId": "Location",
    "locationName": "Emsworth PRV",
    "locationReference": "EmsworthPRV",
    "isShared": false,
    "locationType": "Inlet",
    "areaId": "7dab74a2-3094-400b-92cc-fd0af0e96032",
    "areaName": "Emsworth",
    "areaRef": "Emsworth",
    "dialUpEntries": [
        {
            "start": 0
        },
        {
            "start": 60,
            "repeat": 15,
            "end": 1440
        },
        {
            "start": 1020
        }
    ]
}

and then the following code

db.select('/dialUpEntries/*[/start >= 0]').destroyAll();

fails to remove all 3 array elements of "dialUpEntries" as when /dialUpEntries/0 is deleted then dialUpEntries/1 and dialUpEntries/2 now refer to wrong and missing entries respectively.

julesfern commented 11 years ago

Well, that's official. I'm a cretin. Sorry you had to fix that, and thanks for patching it yourself :)

dokie commented 11 years ago

Hey not at all as the module is awesome for what I'm using it for. Thanks for responding so fast too as I can then revert back to your npm soon.

julesfern commented 11 years ago

Yep, there are a few issues that were fixed recently so I'll do my best to get a new release notes + NPM package out this weekend.