Skip to content

Commit

Permalink
Merge pull request #940 from Mazyod/master
Browse files Browse the repository at this point in the history
Fix nested key traversal
  • Loading branch information
tristanhimmelman authored May 29, 2018
2 parents 9523b40 + 7517dee commit 8ec53e6
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Sources/Map.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,18 @@ private func valueFor(_ keyPathComponents: ArraySlice<String>, dictionary: [Stri
}

if let keyPath = keyPathComponents.first {
let isTail = keyPathComponents.count == 1
let object = dictionary[keyPath]
if object is NSNull {
return (true, nil)
return (isTail, nil)
} else if keyPathComponents.count > 1, let dict = object as? [String: Any] {
let tail = keyPathComponents.dropFirst()
return valueFor(tail, dictionary: dict)
} else if keyPathComponents.count > 1, let array = object as? [Any] {
let tail = keyPathComponents.dropFirst()
return valueFor(tail, array: array)
} else {
return (object != nil, object)
return (isTail && object != nil, object)
}
}

Expand All @@ -179,18 +180,19 @@ private func valueFor(_ keyPathComponents: ArraySlice<String>, array: [Any]) ->
if let keyPath = keyPathComponents.first,
let index = Int(keyPath) , index >= 0 && index < array.count {

let isTail = keyPathComponents.count == 1
let object = array[index]

if object is NSNull {
return (true, nil)
return (isTail, nil)
} else if keyPathComponents.count > 1, let array = object as? [Any] {
let tail = keyPathComponents.dropFirst()
return valueFor(tail, array: array)
} else if keyPathComponents.count > 1, let dict = object as? [String: Any] {
let tail = keyPathComponents.dropFirst()
return valueFor(tail, dictionary: dict)
} else {
return (true, object)
return (isTail, object)
}
}

Expand Down

0 comments on commit 8ec53e6

Please sign in to comment.