Bug#895004: dpkg: Dpkg::Version manpage documents workflows that reject version "0"

2018-04-11 Thread Guillem Jover
Control: severity -1 normal

Hi!

On Fri, 2018-04-06 at 07:18:49 +0200, Niels Thykier wrote:
> Package: dpkg
> Version: 1.19.0.5
> Severity: minor

> There are some examples in Dpkg::Version that (if followed) would
> imply that the problem will reject the version number "0" despite it
> being valid.
> 
> Example:
> """
> boolean evaluation
> When the Dpkg::Version object is used in a boolean evaluation (for 
> example in "if ($v)" or "$v || 'default'") it returns its string 
> representation if the
> version stored is valid ($v->is_valid()) and undef otherwise.
> """
> 
> This gives "surprising" results for version 0, which has a string
> value that is considered false.  To improve the correctness of the
> examples.  I have come to the following alternative examples:
> 
>   -> "if (defined($v) and $v->is_valid())"
>   -> "$v // 'default'"
> 
> Sadly, the "if"-case is no longer elegant but that is the best I could
> come up with that worked if $v is possibly undef and still have it
> work.  However, it no longer serves as a good example for "boolean
> evaluation" (but neither did the original if you want to support the
> version "0").

As mentioned on IRC, the current behavior is just broken, and it was
changed from the correct and expected one to fix a problem in
dpkg-shlibdeps, instead of fixing it there and avoiding breaking
Dpkg::Version users.

I've fixed this now locally, while also making the code emit a warning
so that users can notice the semantic change, it will be possible to
do a targetted silencing of the warning, once the code has been
verified or fixed.

Thanks,
Guillem



Bug#895004: dpkg: Dpkg::Version manpage documents workflows that reject version "0"

2018-04-05 Thread Niels Thykier
Package: dpkg
Version: 1.19.0.5
Severity: minor

Hi,

There are some examples in Dpkg::Version that (if followed) would
imply that the problem will reject the version number "0" despite it
being valid.

Example:
"""
boolean evaluation
When the Dpkg::Version object is used in a boolean evaluation (for 
example in "if ($v)" or "$v || 'default'") it returns its string representation 
if the
version stored is valid ($v->is_valid()) and undef otherwise.
"""

This gives "surprising" results for version 0, which has a string
value that is considered false.  To improve the correctness of the
examples.  I have come to the following alternative examples:

  -> "if (defined($v) and $v->is_valid())"
  -> "$v // 'default'"

Sadly, the "if"-case is no longer elegant but that is the best I could
come up with that worked if $v is possibly undef and still have it
work.  However, it no longer serves as a good example for "boolean
evaluation" (but neither did the original if you want to support the
version "0").

I have used the below to experiment/find the bug:
"""
use v5.20;
use Dpkg::Version;

my $v = Dpkg::Version->new("0");
my $v_or_fallback = $v || 'default';
my $v_dor_fallback = $v // 'default';

say "$v is valid" if $v->is_valid;

if ($v) {
   say "$v is true";
} else {
  say "$v is false";
}

say "\$v || 'default' = $v_or_fallback";
say "\$v // 'default' = $v_dor_fallback";
"""

Result:

"""
0 is valid
0 is false
$v || 'default' = default
$v // 'default' = 0
"""


Thanks,
~Niels