Title: Incorrect debian version comparisons with tilde · Issue #3 · memory/python-dpkg · GitHub
Open Graph Title: Incorrect debian version comparisons with tilde · Issue #3 · memory/python-dpkg
X Title: Incorrect debian version comparisons with tilde · Issue #3 · memory/python-dpkg
Description: The tilde in debian versions sorts before anything else, meaning version 1.2.3-1~deb7u1 is less than 1.2.3-1. python-dpkg does not properly sort these versions. The check here triggers an IndexError: python-dpkg/pydpkg/__init__.py Line 4...
Open Graph Description: The tilde in debian versions sorts before anything else, meaning version 1.2.3-1~deb7u1 is less than 1.2.3-1. python-dpkg does not properly sort these versions. The check here triggers an IndexErro...
X Description: The tilde in debian versions sorts before anything else, meaning version 1.2.3-1~deb7u1 is less than 1.2.3-1. python-dpkg does not properly sort these versions. The check here triggers an IndexErro...
Opengraph URL: https://github.com/memory/python-dpkg/issues/3
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Incorrect debian version comparisons with tilde","articleBody":"The tilde in debian versions sorts before anything else, meaning version 1.2.3-1~deb7u1 is less than 1.2.3-1. python-dpkg does not properly sort these versions.\r\n\r\nThe check here triggers an IndexError:\r\nhttps://github.com/memory/python-dpkg/blob/dc88cfbbd0f052a6808f339486bf9b7e991c137c/pydpkg/__init__.py#L497\r\n\r\nThis index error is caught here:\r\nhttps://github.com/memory/python-dpkg/blob/dc88cfbbd0f052a6808f339486bf9b7e991c137c/pydpkg/__init__.py#L513-L515\r\n\r\nThe assumption that since rev1 is longer than rev2 it is greater is not correct because of the tilde.\r\n\r\nBelow are some tests that can be added to `test_dpkg.py` to catch this error. I've also added a few other tests for completeness and to catch some other edge cases.\r\n\r\n```diff\r\ndiff --git a/tests/test_dpkg.py b/tests/test_dpkg.py\r\nindex 2bec9b7..8dd1564 100644\r\n--- a/tests/test_dpkg.py\r\n+++ b/tests/test_dpkg.py\r\n@@ -187,6 +187,9 @@ class DpkgVersionsTest(unittest.TestCase):\r\n self.assertEqual(Dpkg.compare_versions('0.0.9', '0.0.10'), -1)\r\n self.assertEqual(Dpkg.compare_versions('0.9.0', '0.10.0'), -1)\r\n self.assertEqual(Dpkg.compare_versions('9.0.0', '10.0.0'), -1)\r\n+ self.assertEqual(Dpkg.compare_versions('1.2.3-1~deb7u1', '1.2.3-1'), -1)\r\n+ self.assertEqual(Dpkg.compare_versions('2.7.4+reloaded2-13ubuntu1', '2.7.4+reloaded2-13+deb9u1'), -1)\r\n+ self.assertEqual(Dpkg.compare_versions('2.7.4+reloaded2-13', '2.7.4+reloaded2-13+deb9u1'), -1)\r\n \r\n # greater than\r\n self.assertEqual(Dpkg.compare_versions('0.0.1-0', '0:0.0.0'), 1)\r\n@@ -195,6 +198,9 @@ class DpkgVersionsTest(unittest.TestCase):\r\n self.assertEqual(Dpkg.compare_versions('0.0.9', '0.0.1'), 1)\r\n self.assertEqual(Dpkg.compare_versions('0.9.0', '0.1.0'), 1)\r\n self.assertEqual(Dpkg.compare_versions('9.0.0', '1.0.0'), 1)\r\n+ self.assertEqual(Dpkg.compare_versions('1.2.3-1', '1.2.3-1~deb7u1'), 1)\r\n+ self.assertEqual(Dpkg.compare_versions('2.7.4+reloaded2-13+deb9u1', '2.7.4+reloaded2-13ubuntu1'), 1)\r\n+ self.assertEqual(Dpkg.compare_versions('2.7.4+reloaded2-13+deb9u1', '2.7.4+reloaded2-13'), 1)\r\n \r\n # unicode me harder\r\n self.assertEqual(Dpkg.compare_versions(u'2:0.0.44-1', u'2:0.0.44-nobin'), -1)\r\n```\r\n\r\nI haven't had the time to try and come up with a solution, but, as a reference, here's another pure-python implementation of version comparison: https://git.launchpad.net/review-tools/tree/reviewtools/debversion.py","author":{"url":"https://github.com/mssalvatore","@type":"Person","name":"mssalvatore"},"datePublished":"2020-11-20T13:12:14Z","url":"https://github.com/memory/python-dpkg/issues/3"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:32cc7c18-1957-addd-392d-8a3b11a961a6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9CFC:2E5652:2849B7D:334AE8A:6B019FD6 |
| html-safe-nonce | d63fd9ce60d3a6887698e4d2c70edae13befcdbe4609c5f72fb468abc79a1f82 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5Q0ZDOjJFNTY1MjoyODQ5QjdEOjMzNEFFOEE6NkIwMTlGRDYiLCJ2aXNpdG9yX2lkIjoiNjAyNzg3MjMyMTI0MTQ1NjU5OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | f6a8d81915a93232f6d65c7736f11257e6c8026a97b8b244ae3ec87f35e28968 |
| hovercard-subject-tag | issue:747480399 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/memory/python-dpkg/3/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ef3691b4cea1b84e7c3752e9da9ef50da0b0037298b959a8fc21b5f519649d4e/memory/python-dpkg/issues/3 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ef3691b4cea1b84e7c3752e9da9ef50da0b0037298b959a8fc21b5f519649d4e/memory/python-dpkg/issues/3 |
| og:image:alt | The tilde in debian versions sorts before anything else, meaning version 1.2.3-1~deb7u1 is less than 1.2.3-1. python-dpkg does not properly sort these versions. The check here triggers an IndexErro... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mssalvatore |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/memory/python-dpkg git https://github.com/memory/python-dpkg.git |
| octolytics-dimension-user_id | 394064 |
| octolytics-dimension-user_login | memory |
| octolytics-dimension-repository_id | 120547428 |
| octolytics-dimension-repository_nwo | memory/python-dpkg |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 120547428 |
| octolytics-dimension-repository_network_root_nwo | memory/python-dpkg |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width