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

debian-packaging: Rework lexical compares to avoid sorting #11

Merged
merged 1 commit into from
Aug 13, 2023

Conversation

refi64
Copy link
Contributor

@refi64 refi64 commented Aug 12, 2023

Sorting the entire character array isn't actually what the deb-version spec implies, and it breaks a variety of version comparisons. In particular, the function used to sort the character array needs to return Equal on two letters to preserve order, but that breaks comparisons between those letters, e.g. this currently returns Greater:

$ dpkg --compare-versions 1a lt 1b; echo $?
0

However, fixing that means that strings with symbols can end up being sorted before letters:

$ dpkg --compare-versions 1b lt 1+a; echo $?
0

This currently only compares properly by accident; the character sorting results in these two arrays:

['b']
['a', '+']

and fixing the letter comparisons breaks this.

This instead merges compare_char in with the main comparison loop (their logic already overlapped a bit) and removes the separate sorting step entirely.

Sorting the entire character array isn't actually what the deb-version
spec implies, and it breaks a variety of version comparisons. In
particular, the function used to sort the character array needs to
return Equal on two letters to preserve order, but that breaks
comparisons between those letters, e.g. this currently returns Greater:

```
$ dpkg --compare-versions 1a lt 1b; echo $?
0
```

However, fixing that means that strings with symbols can end up being
sorted *before* letters:

```
$ dpkg --compare-versions 1b lt 1+a; echo $?
0
```

This currently only compares properly by accident; the character sorting
results in these two arrays:

```
['b']
['a', '+']
```

and fixing the letter comparisons breaks this.

This instead merges compare_char in with the main comparison loop
(their logic already overlapped a bit) and removes the separate sorting
step entirely.

Signed-off-by: Ryan Gonzalez <ryan.gonzalez@collabora.com>
Copy link
Owner

@indygreg indygreg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the bug report and the fix! The new code is definitely better than what came before.

I wasn't planning a release of this crate for a while. But if you'd like me to ship a fix, please let me know.

@indygreg indygreg merged commit 0a04d61 into indygreg:main Aug 13, 2023
12 of 16 checks passed
@refi64
Copy link
Contributor Author

refi64 commented Aug 14, 2023

I wasn't planning a release of this crate for a while. But if you'd like me to ship a fix, please let me know.

No issues here, I can just point to the git repo for now.

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.

None yet

2 participants