Skip to content

Wrong array index processed #3

@knopkem

Description

@knopkem

Consider the following example:

` QJsonArray arr;
{
QJsonObject obj;
obj["name"] = "John";
obj["id"] = "1";
arr.push_back(obj);
}
{
QJsonObject obj;
obj["name"] = "Jane";
obj["id"] = "2";
arr.push_back(obj);
}

QJsonDocument doc(arr);
modifyJsonValue(doc, "[1].id", 3);
qDebug() << doc;

This results in:[{"id":"1","name ":"John"},{"id":3,"name":"John"}]`

The issue seems to be Ln 121:
subValue = destValue.toArray()[usedPropertyName.toInt()];
usedPropertyName is empty which results in casting to 0 instead of the actual index (1). Replacing the line with:
subValue = destValue.toArray()[arrayIndex];
seems to work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions