FS#49093 - [vercmp] vercmp '' foo reports 1

Attached to Project: Pacman
Opened by Alad Wenter (Alad) - Tuesday, 26 April 2016, 12:26 GMT
Last edited by Eli Schwartz (eschwartz) - Friday, 19 January 2018, 04:48 GMT
Task Type Bug Report
Category General
Status Closed
Assigned To Eli Schwartz (eschwartz)
Architecture All
Severity Low
Priority Normal
Reported Version 5.0.1
Due in Version 5.1.0
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

Running vercmp with the first argument an empty string, and the second an argument starting with a letter, results in 1:

% vercmp '' r123.foo
1

While no argument is -1:

% vercmp r123.foo
-1

As I understand -1 is the correct result, as an existing version should always be newer than a non-existing one.
This task depends upon

Closed by  Eli Schwartz (eschwartz)
Friday, 19 January 2018, 04:48 GMT
Reason for closing:  Fixed
Additional comments about closing:  git commit d911438352
Comment by msrd0 (msrd0) - Tuesday, 26 April 2016, 18:45 GMT
Note that if you remove the leading 'r' from the version, vercmp behaves like the exact opposite, which seems ok for me since I've never seen a version not starting with a number.
Comment by Alad Wenter (Alad) - Tuesday, 26 April 2016, 19:21 GMT
Many VCS packages use pkgver starting with a letter:

https://wiki.archlinux.org/index.php/VCS_package_guidelines
Comment by Dave Reisner (falconindy) - Tuesday, 26 April 2016, 22:06 GMT
Could you explain why this is a meaningful/helpful distinction? A PKGBUILD without a pkgver will be rejected by makepkg. If you circumvent this, a package without a version will be rejected by pacman on installation.
Comment by Alad Wenter (Alad) - Wednesday, 27 April 2016, 19:07 GMT
Well, vercmp is useful in other cases, such as comparing sync/local versions (with pacman --print or expac) against the AUR RPC (with curl/json). If either string is empty, you'd have to be aware of the limitation, and workaround by e.g. setting -1 yourself if the variable is empty.

Note that vercmp also behaves inconsistently if you supply it a single argument:

% vercmp 123
1
% vercmp r123
-1

I'm not sure on the logic behind this (if any), but at least it should be documented.
Comment by Andrew Gregory (andrewgregory) - Friday, 29 April 2016, 03:38 GMT
I am confused by the references to calling vercmp with a single argument. I'm really not even sure why we allow that. vercmp is for comparing two version strings; calling it with just one doesn't make sense. So, I don't think its output with one argument is relevant here.

Treating the empty string as a "non-existent" version also doesn't make sense. Something that does not exist cannot be newer or older than something else. Alphabetic components of version strings are older than any non-alphabetic component, including the empty string. That's why 1.0alpha is older than 1.0 and why you see the difference between `vercmp 123` and `vercmp r123`.
Comment by Alad Wenter (Alad) - Friday, 29 April 2016, 07:51 GMT
In that case, I would suggest to:

1. Only allow calling vercmp with two arguments (3+ are also allowed with v5.0.1)

2. Add "Alphabetic components of version strings are older than any non-alphabetic component, including the empty string." to vercmp(8), clarifying the "Version comparison operates as follows:" section.
Comment by Eli Schwartz (eschwartz) - Wednesday, 13 December 2017, 22:50 GMT
I thoroughly agree that vercmp should not allow anything other than exactly two arguments (unless we exit early after detecting --help as the first argument).

This should be really simple to fix, e.g. the attached patch. I'm not sure whether to provide an error message though -- and if so, do we need to drag in gettext o_O as well?
(That being said, we don't translate the current help text so probably not...)
Comment by Eli Schwartz (eschwartz) - Sunday, 17 December 2017, 19:44 GMT

Loading...