bbc / lrud

Left, Right, Up, Down. A spatial navigation library for devices with input via directional controls.
Apache License 2.0
98 stars 21 forks source link

Fixing infinite climbUp, fixes #79 #80

Closed adrian-wozniak closed 3 years ago

adrian-wozniak commented 3 years ago

This PR fixes node path resolution when given nodeId is not defined.

Description

getPathForNodeId method didn't check whether provided nodeId is defined or not. As a result it was looking for node paths ending with '.undefined' or '.null'. If nodes with such ids exist then climbUp method was making infinite scan failing with Maximum call stack size exceeded error. When root node was reached, the climbing should stop, but instead root's undefined parent was resolved as path to node with 'undefined' id (string with 9 chars word) and climbing was continued until, again, root node was reached, and the story begins.

Motivation and Context

Having nodes with 'undefined' or 'null' ids is not common situation, and may point that similar bug (concatenating null/undefined variable with string) is somewhere in LRUD user's code. Nevertheless, 'undefined' and 'null' are fully-flagged ids that shouldn't cause infinite climbing.

How Has This Been Tested?

Fix was tested by unit tests and manually in app using LRUD library where such issue was found.

Screenshots (if appropriate):

Types of changes

Checklist:

adrian-wozniak commented 3 years ago

@jordanholt Could I ask to to tale a look on that?