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

Avoid throwing an exception when sorting identical paths #90

Merged
merged 7 commits into from
Dec 10, 2021

Conversation

lihaoyi
Copy link
Member

@lihaoyi lihaoyi commented Dec 10, 2021

Fixes #44

The basic issue is that our loops i is being incremented and fed into getSegment 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 the i += 1 such that it takes place immediately before the out-of-bounds check, to ensure it is always in bounds when we pass it to getSegment

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 comparison

Adds a test case that reproduces the failure on master, passes on this PR

Review by @lefou

@lihaoyi lihaoyi requested a review from lefou December 10, 2021 07:42
@lihaoyi lihaoyi merged commit b43111f into master Dec 10, 2021
@lefou lefou deleted the fix-path-sort branch July 28, 2022 09:07
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.

Ordering[os.Path] impl is broken. Trivial fix included.
2 participants