Skip Menu |

This queue is for tickets about the version CPAN distribution.

Report information
The Basics
Id: 114712
Status: resolved
Priority: 0/
Queue: version

People
Owner: Nobody in particular
Requestors: bob.kleemann [...] everyonecounts.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Regexes cannot properly parse "snapshot-1.2.3ga-001-432"
Date: Wed, 25 May 2016 13:24:55 -0700
To: bug-version [...] rt.cpan.org
From: Bob Kleemann <bob.kleemann [...] everyonecounts.com>
It seems that the version regex does not do longest match first. $ perl -Mversion=0.77 -E 'say $version::VERSION; $v = "snapshot-1.2.3ga-001-432"; say version->parse( $v =~ /($version::LAX)/ ); say version->parse( $v =~ /($version::STRICT)/ )' 0.9912 1. 1.2 I would expect it to print out "1.2.3", or something similar.
On Wed May 25 16:25:07 2016, bob.kleemann@everyonecounts.com wrote: Show quoted text
> It seems that the version regex does not do longest match first. > > $ perl -Mversion=0.77 -E 'say $version::VERSION; $v = > "snapshot-1.2.3ga-001-432"; say version->parse( $v =~ > /($version::LAX)/ ); say > version->parse( $v =~ /($version::STRICT)/ )' > 0.9912 > 1. > 1.2 > > I would expect it to print out "1.2.3", or something similar.
Those regexes were never really intended to be used to capture a version out of a random string. They were primarily intended to be used for is_strict() and is_lax(). However, I have discovered that because of Perl's greedy matching algorithm, several of the alternations need to be swapped so that the longest match is found first (which is why you got the trailing decimal). This works now: $ perl -I blib/lib/ -I blib/arch/ -Mversion -wE 'say $version::VERSION; $v = "snapshot-1.2.3ga-001-432"; say $v =~ /($version::LAX)/;' 0.9916 1.2.3 I will point out that your example will never work with $version::STRICT because that requires a leading 'v' for dotted-decimal versions. John
Subject: Re: [rt.cpan.org #114712] Regexes cannot properly parse "snapshot-1.2.3ga-001-432"
Date: Thu, 26 May 2016 16:49:19 -0700
To: bug-version [...] rt.cpan.org
From: Bob Kleemann <bob.kleemann [...] everyonecounts.com>
Why include the trailing . in a version number? Shouldn't every dot be followed by a number or underscore-number? On Wed, May 25, 2016 at 5:56 PM, John Peacock via RT < bug-version@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=114712 > > > On Wed May 25 16:25:07 2016, bob.kleemann@everyonecounts.com wrote:
> > It seems that the version regex does not do longest match first. > > > > $ perl -Mversion=0.77 -E 'say $version::VERSION; $v = > > "snapshot-1.2.3ga-001-432"; say version->parse( $v =~ > > /($version::LAX)/ ); say > > version->parse( $v =~ /($version::STRICT)/ )' > > 0.9912 > > 1. > > 1.2 > > > > I would expect it to print out "1.2.3", or something similar.
> > Those regexes were never really intended to be used to capture a version > out of a random string. They were primarily intended to be used for > is_strict() and is_lax(). > > However, I have discovered that because of Perl's greedy matching > algorithm, several of the alternations need to be swapped so that the > longest match is found first (which is why you got the trailing decimal). > This works now: > > $ perl -I blib/lib/ -I blib/arch/ -Mversion -wE 'say $version::VERSION; $v > = > "snapshot-1.2.3ga-001-432"; say $v =~ /($version::LAX)/;' > 0.9916 > 1.2.3 > > I will point out that your example will never work with $version::STRICT > because that requires a leading 'v' for dotted-decimal versions. > > John > >
On Thu May 26 19:49:30 2016, bob.kleemann@everyonecounts.com wrote: Show quoted text
> Why include the trailing . in a version number? Shouldn't every dot be > followed by a number or underscore-number?
Because $version::LAX is very lax, in that it accepts anything that Perl itself considers a valid floating point number (which includes 1. and .01). However, by swapping several alternations internally, the regexes match the longest value instead of the shortest. I'm releasing 0.9917 momentarily.