Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JsonParserUtility::extractValue ensure to not return garbage value #359

Merged

Conversation

herve-er
Copy link
Contributor

@herve-er herve-er commented Oct 24, 2024

Before this PR, if the key was not found or was found but empty, the JsonParserUtility::extractValue method would return true and leave the val variable unchanged.

This behavior caused issues in the following scenario:

if (!JsonParserUtility::extractValue(actionObj, fileTypeKey, tmpStr)) {
    return ExitCode::BackError;
}
actionInfo.snapshotItem.setType(tmpStr == fileKey ? NodeType::File : NodeType::Directory);

if (!JsonParserUtility::extractValue(actionObj, symbolicLinkKey, tmpStr, false)) {
    return ExitCode::BackError;
}
actionInfo.snapshotItem.setIsLink(!tmpStr.empty());

If symbolicLinkKey was not found, tmpStr would retain the value of fileTypeKey, mistakenly treating the item as a link by assuming the link URL was not empty.

This PR modifies extractValue to clear the val variable when the key is not found, preventing this unintended behavior.

@herve-er herve-er requested a review from a team as a code owner October 24, 2024 12:17
@herve-er herve-er marked this pull request as draft October 24, 2024 12:17
@herve-er herve-er marked this pull request as ready for review October 24, 2024 12:17
Copy link

@ClementKunz ClementKunz merged commit 65d9d3f into develop Oct 24, 2024
7 checks passed
@ClementKunz ClementKunz deleted the KDESKTOP-1320-New-file-wrongly-considered-as-link branch October 24, 2024 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants