Avoid throwing an exception when sorting identical paths #90
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #44
The basic issue is that our loops
i
is being incremented and fed intogetSegment
before the out-of-bounds check. Thus if two paths are identical, it ends up overshooting the end of the sequence of segments, resulting in the error reported. The fix is to order thei += 1
such that it takes place immediately before the out-of-bounds check, to ensure it is always in bounds when we pass it togetSegment
The
i == xSegCount
check at the bottom was also incorrect. Just because we've hit the end of the list doesn't mean the two paths are equal, as the point of the loop is to find the first non-equal string segment so we can compare them. Thus we should compare the two string segments every time: if they are equal and we haven't run out, we loop another time, otherwise we return the result of the comparisonAdds a test case that reproduces the failure on master, passes on this PR
Review by @lefou