Fixing cmpfunc: fix sort to distinguish prefix-overlapping query keys#438
Fixing cmpfunc: fix sort to distinguish prefix-overlapping query keys#438arpitguptagithub wants to merge 2 commits intocurl:masterfrom
Conversation
296d7f5 to
7d9f271
Compare
There was a problem hiding this comment.
Pull request overview
This PR fixes query sorting determinism in trurl by making the query-pair comparator distinguish strings where one is a prefix of the other, and adds a regression test intended to cover prefix-overlapping query keys.
Changes:
- Update
cmpfuncto break ties when one query pair is a strict prefix of another (shorter sorts first). - Add a new
--sort-querytest case intended to verify deterministic ordering with prefix-overlapping keys.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
trurl.c |
Adjusts the qsort comparator so prefix-overlapping strings no longer compare equal. |
tests.json |
Adds a regression test for --sort-query ordering. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@bagder ig now this will be okay, have a look? please |
Please rebase your branch ontop of master and force-push |
When one query key is a prefix of another (e.g. 'a' vs 'ab'), the comparison function returned 0 (equal), making --sort-query produce non-deterministic order for such pairs. Fix by returning the length difference when the common prefix matches, so shorter keys sort before longer ones. Add a test with prefix-overlapping query keys to verify deterministic sort order.
5acbd43 to
61e8698
Compare
61e8698 to
9546979
Compare
|
FYI I have added a regresiion test- anyhow adding the excludes annotation skips them on uppercase-hex builds, matching the pattern already used by other tests in the repo (e.g. tests around line 717). These are pre-existing failures unrelated to the cmpfunc fix. Hope thats fine. |
When one query key is a prefix of another (e.g. 'a' vs 'ab'), the comparison function returned 0 (equal), making --sort-query produce non-deterministic order for such pairs.
I fix it by returning the length difference when the common prefix matches, so shorter keys sort before longer ones.
Adding a test with prefix-overlapping query keys to verify deterministic sort order.