Skip to content

Commit

Permalink
fix string comparisons with $] to use numeric comparison instead
Browse files Browse the repository at this point in the history
The fix follows Zefram's suggestion from
https://www.nntp.perl.org/group/perl.perl5.porters/2012/05/msg186846.html

> On older perls, however, $] had a numeric value that was built up using
> floating-point arithmetic, such as 5+0.006+0.000002.  This would not
> necessarily match the conversion of the complete value from string form
> [perl #72210].  You can work around that by explicitly stringifying
> $] (which produces a correct string) and having *that* numify (to a
> correctly-converted floating point value) for comparison.  I cultivate
> the habit of always stringifying $] to work around this, regardless of
> the threshold where the bug was fixed.  So I'd write
>
>     use if "$]" >= 5.014, warnings => "non_unicode";
  • Loading branch information
book committed Dec 12, 2024
1 parent 332d97a commit a16bffc
Show file tree
Hide file tree
Showing 50 changed files with 83 additions and 83 deletions.
4 changes: 2 additions & 2 deletions cpan/CPAN-Meta-Requirements/t/from-hash.t
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ for my $string (10, '>= 2, <= 9, != 7') {

SKIP: {
skip "Can't tell v-strings from strings until 5.8.1", 1
unless $] gt '5.008';
unless "$]" > '5.008';
my $string_hash = {
Left => 10,
Shared => '= 2',
Expand Down Expand Up @@ -87,7 +87,7 @@ SKIP: {

SKIP: {
skip "Can't tell v-strings from strings until 5.8.1", 2
unless $] gt '5.008';
unless "$]" > '5.008';
my $string_hash = {
Left => 10,
Shared => v50.44.60,
Expand Down
2 changes: 1 addition & 1 deletion cpan/CPAN-Meta-YAML/t/01_compile.t
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ BEGIN {
use Test::More 0.88;

# Check their perl version
ok( $] ge '5.008001', "Your perl is new enough" );
ok( "$]" >= '5.008001', "Your perl is new enough" );

# Does the module load
require_ok( 'CPAN::Meta::YAML' );
Expand Down
2 changes: 1 addition & 1 deletion cpan/CPAN-Meta/lib/CPAN/Meta.pm
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ sub save {
my ($self, $file, $options) = @_;

my $version = $options->{version} || '2';
my $layer = $] ge '5.008001' ? ':utf8' : '';
my $layer = "$]" >= '5.008001' ? ':utf8' : '';

if ( $version ge '2' ) {
carp "'$file' should end in '.json'"
Expand Down
10 changes: 5 additions & 5 deletions cpan/HTTP-Tiny/lib/HTTP/Tiny.pm
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ sub _prepare_headers_and_cb {
}
elsif ( length $args->{content} ) {
my $content = $args->{content};
if ( $] ge '5.008' ) {
if ( "$]" >= '5.008' ) {
utf8::downgrade($content, 1)
or die(qq/Wide character in request message body\n/);
}
Expand Down Expand Up @@ -1032,7 +1032,7 @@ my $unsafe_char = qr/[^A-Za-z0-9\-\._~]/;
sub _uri_escape {
my ($self, $str) = @_;
return "" if !defined $str;
if ( $] ge '5.008' ) {
if ( "$]" >= '5.008' ) {
utf8::encode($str);
}
else {
Expand Down Expand Up @@ -1189,7 +1189,7 @@ sub write {
@_ == 2 || die(q/Usage: $handle->write(buf)/ . "\n");
my ($self, $buf) = @_;

if ( $] ge '5.008' ) {
if ( "$]" >= '5.008' ) {
utf8::downgrade($buf, 1)
or die(qq/Wide character in write()\n/);
}
Expand Down Expand Up @@ -1474,7 +1474,7 @@ sub write_content_body {
defined $data && length $data
or last;

if ( $] ge '5.008' ) {
if ( "$]" >= '5.008' ) {
utf8::downgrade($data, 1)
or die(qq/Wide character in write_content()\n/);
}
Expand Down Expand Up @@ -1521,7 +1521,7 @@ sub write_chunked_body {
defined $data && length $data
or last;

if ( $] ge '5.008' ) {
if ( "$]" >= '5.008' ) {
utf8::downgrade($data, 1)
or die(qq/Wide character in write_chunked_body()\n/);
}
Expand Down
4 changes: 2 additions & 2 deletions cpan/Pod-Simple/lib/Pod/Simple.pm
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ BEGIN {
die "MANY_LINES is too small (", MANY_LINES(), ")!\nAborting";
}
if(defined &UNICODE) { }
elsif($] >= 5.008) { *UNICODE = sub() {1} }
elsif("$]" >= 5.008) { *UNICODE = sub() {1} }
else { *UNICODE = sub() {''} }
}
if(DEBUG > 2) {
Expand All @@ -42,7 +42,7 @@ if(DEBUG > 2) {
}

# The NO BREAK SPACE and SOFT HYHPEN are used in several submodules.
if ($] ge 5.007_003) { # On sufficiently modern Perls we can handle any
if ("$]" >= 5.007_003) { # On sufficiently modern Perls we can handle any
# character set
$Pod::Simple::nbsp = chr utf8::unicode_to_native(0xA0);
$Pod::Simple::shy = chr utf8::unicode_to_native(0xAD);
Expand Down
10 changes: 5 additions & 5 deletions cpan/Pod-Simple/lib/Pod/Simple/BlackBox.pm
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ sub my_qr ($$) {
my ($input_re, $should_match) = @_;
# XXX could have a third parameter $shouldnt_match for extra safety

my $use_utf8 = ($] le 5.006002) ? 'use utf8;' : "";
my $use_utf8 = ("$]" <= 5.006002) ? 'use utf8;' : "";

my $re = eval "no warnings; $use_utf8 qr/$input_re/";
#print STDERR __LINE__, ": $input_re: $@\n" if $@;
Expand Down Expand Up @@ -93,7 +93,7 @@ my $deprecated_re = my_qr('\p{IsDeprecated}', "\x{149}");
$deprecated_re = qr/\x{149}/ unless $deprecated_re;

my $utf8_bom;
if (($] ge 5.007_003)) {
if (("$]" >= 5.007_003)) {
$utf8_bom = "\x{FEFF}";
utf8::encode($utf8_bom);
} else {
Expand Down Expand Up @@ -266,13 +266,13 @@ sub parse_lines { # Usage: $parser->parse_lines(@lines)
# XXX probably if the line has E<foo> that evaluates to illegal CP1252,
# then it is UTF-8. But we haven't processed E<> yet.

goto set_1252 if $] lt 5.006_000; # No UTF-8 on very early perls
goto set_1252 if "$]" <= 5.006_000; # No UTF-8 on very early perls

my $copy;

no warnings 'utf8';

if ($] ge 5.007_003) {
if ("$]" >= 5.007_003) {
$copy = $line;

# On perls that have this function, we can use it to easily see if the
Expand All @@ -286,7 +286,7 @@ sub parse_lines { # Usage: $parser->parse_lines(@lines)
}
else { # ASCII, no decode(): do it ourselves using the fundamental
# characteristics of UTF-8
use if $] le 5.006002, 'utf8';
use if "$]" <= 5.006002, 'utf8';

my $char_ord;
my $needed; # How many continuation bytes to gobble up
Expand Down
2 changes: 1 addition & 1 deletion cpan/Pod-Simple/lib/Pod/Simple/DumpAsXML.pm
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ sub _handle_element_end {
sub _xml_escape {
foreach my $x (@_) {
# Escape things very cautiously:
if ($] ge 5.007_003) {
if ("$]" >= 5.007_003) {
$x =~ s/([^-\n\t !\#\$\%\(\)\*\+,\.\~\/\:\;=\?\@\[\\\]\^_\`\{\|\}abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789])/'&#'.(utf8::native_to_unicode(ord($1))).';'/eg;
} else { # Is broken for non-ASCII platforms on early perls
$x =~ s/([^-\n\t !\#\$\%\(\)\*\+,\.\~\/\:\;=\?\@\[\\\]\^_\`\{\|\}abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789])/'&#'.(ord($1)).';'/eg;
Expand Down
8 changes: 4 additions & 4 deletions cpan/Pod-Simple/lib/Pod/Simple/HTML.pm
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ sub section_name_tidy {
$section =~ s/^\s+//;
$section =~ s/\s+$//;
$section =~ tr/ /_/;
if ($] ge 5.006) {
if ("$]" >= 5.006) {
$section =~ s/[[:cntrl:][:^ascii:]]//g; # drop crazy characters
} elsif ('A' eq chr(65)) { # But not on early EBCDIC
$section =~ tr/\x00-\x1F\x80-\x9F//d;
Expand All @@ -724,7 +724,7 @@ sub general_url_escape {
# A pretty conservative escaping, behoovey even for query components
# of a URL (see RFC 2396)

if ($] ge 5.007_003) {
if ("$]" >= 5.007_003) {
$string =~ s/([^-_\.!~*()abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789])/sprintf('%%%02X',utf8::native_to_unicode(ord($1)))/eg;
} else { # Is broken for non-ASCII platforms on early perls
$string =~ s/([^-_\.!~*()abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789])/sprintf('%%%02X',ord($1))/eg;
Expand Down Expand Up @@ -862,7 +862,7 @@ sub esc { # a function.
@_ = splice @_; # break aliasing
} else {
my $x = shift;
if ($] ge 5.007_003) {
if ("$]" >= 5.007_003) {
$x =~ s/([^-\n\t !\#\$\%\(\)\*\+,\.\~\/\:\;=\?\@\[\\\]\^_\`\{\|\}abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789])/'&#'.(utf8::native_to_unicode(ord($1))).';'/eg;
} else { # Is broken for non-ASCII platforms on early perls
$x =~ s/([^-\n\t !\#\$\%\(\)\*\+,\.\~\/\:\;=\?\@\[\\\]\^_\`\{\|\}abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789])/'&#'.(ord($1)).';'/eg;
Expand All @@ -873,7 +873,7 @@ sub esc { # a function.
foreach my $x (@_) {
# Escape things very cautiously:
if (defined $x) {
if ($] ge 5.007_003) {
if ("$]" >= 5.007_003) {
$x =~ s/([^-\n\t !\#\$\%\(\)\*\+,\.\~\/\:\;=\?\@\[\\\]\^_\`\{\|\}abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789])/'&#'.(utf8::native_to_unicode(ord($1))).';'/eg
} else { # Is broken for non-ASCII platforms on early perls
$x =~ s/([^-\n\t !\#\$\%\(\)\*\+,\.\~\/\:\;=\?\@\[\\\]\^_\`\{\|\}abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789])/'&#'.(ord($1)).';'/eg
Expand Down
4 changes: 2 additions & 2 deletions cpan/Pod-Simple/lib/Pod/Simple/RTF.pm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ sub to_uni ($) { # Convert native code point to Unicode
my $x = shift;

# Broken for early EBCDICs
$x = chr utf8::native_to_unicode(ord $x) if $] ge 5.007_003
$x = chr utf8::native_to_unicode(ord $x) if "$]" >= 5.007_003
&& ord("A") != 65;
return $x;
}
Expand Down Expand Up @@ -549,7 +549,7 @@ my $other_unicode =
Pod::Simple::BlackBox::my_qr('([\x{10000}-\x{10FFFF}])', "\x{10000}");

sub esc_uni($) {
use if $] le 5.006002, 'utf8';
use if "$]" >= 5.006002, 'utf8';

my $x = shift;

Expand Down
2 changes: 1 addition & 1 deletion cpan/Pod-Simple/lib/Pod/Simple/XMLOutStream.pm
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ sub _handle_element_end {
sub _xml_escape {
foreach my $x (@_) {
# Escape things very cautiously:
if ($] ge 5.007_003) {
if ("$]" >= 5.007_003) {
$x =~ s/([^-\n\t !\#\$\%\(\)\*\+,\.\~\/\:\;=\?\@\[\\\]\^_\`\{\|\}abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789])/'&#'.(utf8::native_to_unicode(ord($1))).';'/eg;
} else { # Is broken for non-ASCII platforms on early perls
$x =~ s/([^-\n\t !\#\$\%\(\)\*\+,\.\~\/\:\;=\?\@\[\\\]\^_\`\{\|\}abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789])/'&#'.(ord($1)).';'/eg;
Expand Down
2 changes: 1 addition & 1 deletion cpan/Pod-Simple/t/ascii_order.pl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ($)
my $string = shift;

return $string if ord("A") == 65
|| $] lt 5.007_003; # Doesn't work on early EBCDIC Perls
|| "$]" < 5.007_003; # Doesn't work on early EBCDIC Perls
my $output = "";
for my $i (0 .. length($string) - 1) {
$output .= chr(utf8::native_to_unicode(ord(substr($string, $i, 1))));
Expand Down
2 changes: 1 addition & 1 deletion cpan/Pod-Simple/t/encod04.t
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use Pod::Simple::XMLOutStream;
my $x97;
my $x91;
my $dash;
if ($] ge 5.007_003) {
if ("$]" >= 5.007_003) {
$x97 = chr utf8::unicode_to_native(0x97);
$x91 = chr utf8::unicode_to_native(0x91);
$dash = '&#8212';
Expand Down
2 changes: 1 addition & 1 deletion cpan/Scalar-List-Utils/t/stack-corruption.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!./perl

BEGIN {
if ($] eq "5.008009" or $] eq "5.010000" or $] le "5.006002") {
if ("$]" == "5.008009" or "$]" == "5.010000" or "$]" <= "5.006002") {
print "1..0 # Skip: known to fail on $]\n";
exit 0;
}
Expand Down
2 changes: 1 addition & 1 deletion cpan/Scalar-List-Utils/t/sum.t
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ SKIP: {
cmp_ok($t, 'gt', 1152921504606846976, 'sum uses IV where it can'); # string comparison because Perl 5.6 does not compare it numerically correctly

SKIP: {
skip "known to fail on $]", 1 if $] le "5.006002";
skip "known to fail on $]", 1 if "$]" <= "5.006002";
$t = sum(1<<60, 1);
cmp_ok($t, '>', 1<<60, 'sum uses IV where it can');
}
Expand Down
6 changes: 3 additions & 3 deletions cpan/Scalar-List-Utils/t/uniq.t
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ is_deeply( [ uniqstr qw( 1 1.0 1E0 ) ],
}

SKIP: {
skip 'Perl 5.007003 with utf8::encode is required', 3 if $] lt "5.007003";
skip 'Perl 5.007003 with utf8::encode is required', 3 if "$]" < "5.007003";
my $warnings = "";
local $SIG{__WARN__} = sub { $warnings .= join "", @_ };

Expand Down Expand Up @@ -99,7 +99,7 @@ is_deeply( [ uniqint 6.1, 6.2, 6.3 ],
}

SKIP: {
skip('UVs are not reliable on this perl version', 2) unless $] ge "5.008000";
skip('UVs are not reliable on this perl version', 2) unless "$]" >= "5.008000";

my $maxbits = $Config{ivsize} * 8 - 1;

Expand Down Expand Up @@ -153,7 +153,7 @@ is( scalar( uniqstr qw( a b c d a b e ) ), 5, 'uniqstr() in scalar context' );
}

SKIP: {
skip('int overload requires perl version 5.8.0', 1) unless $] ge "5.008000";
skip('int overload requires perl version 5.8.0', 1) unless "$]" >= "5.008000";

package Googol;

Expand Down
2 changes: 1 addition & 1 deletion cpan/Scalar-List-Utils/t/uniqnum.t
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ SKIP: {
# uniqnum not confused by IV'ified floats
SKIP: {
# This fails on 5.6 and isn't fixable without breaking a lot of other tests
skip 'This perl version gets confused by IVNV dualvars', 1 if $] lt '5.008000';
skip 'This perl version gets confused by IVNV dualvars', 1 if "$]" <= '5.008000';
my @nums = ( 2.1, 2.2, 2.3 );
my $dummy = sprintf "%d", $_ for @nums;

Expand Down
2 changes: 1 addition & 1 deletion cpan/Test-Harness/lib/TAP/Harness.pm
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ Any keys for which the value is C<undef> will be ignored.
warn "CPAN::Meta::YAML required to process $rulesfile" ;
return;
}
my $layer = $] lt "5.008" ? "" : ":encoding(UTF-8)";
my $layer = "$]" < "5.008" ? "" : ":encoding(UTF-8)";
open my $fh, "<$layer", $rulesfile
or die "Couldn't open $rulesfile: $!";
my $yaml_text = do { local $/; <$fh> };
Expand Down
2 changes: 1 addition & 1 deletion cpan/Test-Simple/lib/Test2/API.pm
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ sub CLONE {

BEGIN {
no warnings 'once';
if($] ge '5.014' || $ENV{T2_CHECK_DEPTH} || $Test2::API::DO_DEPTH_CHECK) {
if("$]" >= '5.014' || $ENV{T2_CHECK_DEPTH} || $Test2::API::DO_DEPTH_CHECK) {
*DO_DEPTH_CHECK = sub() { 1 };
}
else {
Expand Down
2 changes: 1 addition & 1 deletion cpan/Test-Simple/lib/Test2/Formatter/TAP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ sub _open_handles {
sub encoding {
my $self = shift;

if ($] ge "5.007003" and @_) {
if ("$]" >= "5.007003" and @_) {
my ($enc) = @_;
my $handles = $self->{+HANDLES};

Expand Down
4 changes: 2 additions & 2 deletions cpan/Test-Simple/lib/Test2/Tools/Tiny.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use strict;
use warnings;

BEGIN {
if ($] lt "5.008") {
if ("$]" < "5.008") {
require Test::Builder::IO::Scalar;
}
}
Expand Down Expand Up @@ -260,7 +260,7 @@ sub capture(&) {

($ok, $e) = try {
# Scalar refs as filehandles were added in 5.8.
if ($] ge "5.008") {
if ("$]" >= "5.008") {
open($out_fh, '>', \$out) or die "Failed to open a temporary STDOUT: $!";
open($err_fh, '>', \$err) or die "Failed to open a temporary STDERR: $!";
}
Expand Down
2 changes: 1 addition & 1 deletion cpan/Test-Simple/t/HashBase.t
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ is($pkg->do_it, 'const', "worked as expected");
}
ok(!$pkg->FOO, "overrode const sub");
{
local $TODO = "known to fail on $]" if $] le "5.006002";
local $TODO = "known to fail on $]" if "$]" <= "5.006002";
is($pkg->do_it, 'const', "worked as expected, const was constant");
}

Expand Down
2 changes: 1 addition & 1 deletion cpan/Test-Simple/t/Legacy/Regression/736_use_ok.t
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ sub capture(&) {
}

{
local $TODO = "known to fail on $]" if $] le "5.006002";
local $TODO = "known to fail on $]" if "$]" <= "5.006002";
my $file = __FILE__;
my $line = __LINE__ + 4;
like(
Expand Down
2 changes: 1 addition & 1 deletion cpan/Test-Simple/t/Legacy/overload_threads.t
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ BEGIN {

use Test::More;

plan skip_all => "known to crash on $]" if $] le "5.006002";
plan skip_all => "known to crash on $]" if "$]" <= "5.006002";

plan tests => 5;

Expand Down
2 changes: 1 addition & 1 deletion cpan/Test-Simple/t/Legacy_And_Test2/preload_diag_note.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use strict;
use warnings;

if ($] lt "5.008") {
if ("$]" < "5.008") {
print "1..0 # SKIP Test cannot run on perls below 5.8.0\n";
exit 0;
}
Expand Down
2 changes: 1 addition & 1 deletion cpan/Test-Simple/t/Test2/behavior/init_croak.t
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ BEGIN {
}
}

skip_all("known to fail on $]") if $] le "5.006002";
skip_all("known to fail on $]") if "$]" <= "5.006002";

$@ = "";
my ($file, $line) = (__FILE__, __LINE__ + 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use Test2::Tools::Tiny;

use Test2::API qw/context/;

skip_all("known to fail on $]") if $] le "5.006002";
skip_all("known to fail on $]") if "$]" <= "5.006002";

sub outer {
my $code = shift;
Expand Down
2 changes: 1 addition & 1 deletion cpan/Test-Simple/t/Test2/modules/API.t
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ like(
"got warning about adding driver too late"
);
};
if ($] le "5.006002") {
if ("$]" <= "5.006002") {
todo("TODO known to fail on $]", $sub1);
} else {
$sub1->();
Expand Down
Loading

0 comments on commit a16bffc

Please sign in to comment.