Skip to content
Snippets Groups Projects
Commit 83f5be4c authored by Ruaan Burger's avatar Ruaan Burger
Browse files

Prevent false positives when dealing with heavily nested objects

parent 93bf3aa2
No related branches found
No related tags found
1 merge request!26Prevent false positives when dealing with heavily nested objects
......@@ -198,6 +198,17 @@ func GetAllChanges(original interface{}, new interface{}) (map[string]interface{
if index := strings.Index(changesJson, split); index > -1 && changesJson != "{" {
// Prevent reverse traversal
if index > lastOccurrence {
// Prevent finding nested keys as opposed to our "change" keys
opener := changesJson[index+len(split)+2 : index+len(split)+3]
// Prevent a "base level" key from matching a nested key
baseLevel := false
if index >= 1 {
containedBy := changesJson[index-1 : index]
if levelsDeep == 0 && (containedBy == "{" || containedBy == "[") {
baseLevel = true
}
}
if (opener == "{" || opener == "[") && !baseLevel {
lastOccurrence = index
lastMatched = split
levelsDeep = sIndex
......@@ -205,6 +216,7 @@ func GetAllChanges(original interface{}, new interface{}) (map[string]interface{
}
}
}
}
// If the "key" is already present, handle it differently
if lastOccurrence > 0 {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment