On Tue, 05 Jul 2016 09:52:46 -0700, zef...@fysh.org wrote:
> The Version class accepts numeric components that contain digits with
> diacritics, and faithfully preserves the grapheme string just as it
> preserves non-ASCII digits.  But these components then behave badly
> in comparisons:
> 
> > Version.new("34\x[308]5") leg Version.new("4")
> Less
> 
> The digit with diacritic effectively terminates the digit sequence,
> for the purpose of finding a numeric value.  This is probably due to
> [perl #128542].  This implies that fixing that bug, making the coercion
> reject such modified digits (as appears to be the intent), would cause
> the Version comparison to signal an error.  That would also be buggy
> behaviour, so Version has a problem distinct from the problem with
> Str.Int.
> 
> -zefram
 
Thanks for the report, however, there's no bug here, as strings are valid
version parts, which is what the diaeresis causes the part to parse as
(as opposed to numbers).

The `leg` operator coerces Versions to strings, and in this case string
`"34\x[308]5"` is Less than `"4"`. The more appropriate operator to compare
versions is `cmp`.

With `cmp`, string parts are always Order::Less than number parts, so to
see the comparison working properly, we'd need to compare versions with 
both of those parts being stringy:

<Zoffix> m: say Version.new("34\x[308]5") cmp Version.new("34\x[308]4")
<camelia> rakudo-moar 2f72fa: OUTPUT«More␤»
<Zoffix> m: say Version.new("34\x[308]5") cmp Version.new("34\x[308]5")
<camelia> rakudo-moar 2f72fa: OUTPUT«Same␤»
<Zoffix> m: say Version.new("34\x[308]5") cmp Version.new("34\x[308]6")
<camelia> rakudo-moar 2f72fa: OUTPUT«Less␤»

This also works with Version literals:
<Zoffix> m: say v34̈5 cmp v34̈6
<camelia> rakudo-moar 2f72fa: OUTPUT«Less␤»
<Zoffix> m: say v34̈5 cmp v34̈5
<camelia> rakudo-moar 2f72fa: OUTPUT«Same␤»
<Zoffix> m: say v34̈5 cmp v34̈4
<camelia> rakudo-moar 2f72fa: OUTPUT«More␤»

Cheers,
ZZ

Reply via email to