Skip to content

Commit e52ef14

Browse files
committed
fix string comparisons with $] to use numeric comparison instead
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";
1 parent a7f5931 commit e52ef14

File tree

52 files changed

+88
-88
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+88
-88
lines changed

cpan/CPAN-Meta-Requirements/t/from-hash.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ for my $string (10, '>= 2, <= 9, != 7') {
4343

4444
SKIP: {
4545
skip "Can't tell v-strings from strings until 5.8.1", 1
46-
unless $] gt '5.008';
46+
unless "$]" > 5.008;
4747
my $string_hash = {
4848
Left => 10,
4949
Shared => '= 2',
@@ -87,7 +87,7 @@ SKIP: {
8787

8888
SKIP: {
8989
skip "Can't tell v-strings from strings until 5.8.1", 2
90-
unless $] gt '5.008';
90+
unless "$]" > 5.008;
9191
my $string_hash = {
9292
Left => 10,
9393
Shared => v50.44.60,

cpan/CPAN-Meta-YAML/t/01_compile.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ BEGIN {
1111
use Test::More 0.88;
1212

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

1616
# Does the module load
1717
require_ok( 'CPAN::Meta::YAML' );

cpan/CPAN-Meta/lib/CPAN/Meta.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ sub save {
398398
my ($self, $file, $options) = @_;
399399

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

403403
if ( $version ge '2' ) {
404404
carp "'$file' should end in '.json'"

cpan/HTTP-Tiny/lib/HTTP/Tiny.pm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ sub _prepare_headers_and_cb {
865865
}
866866
elsif ( length $args->{content} ) {
867867
my $content = $args->{content};
868-
if ( $] ge '5.008' ) {
868+
if ( "$]" >= 5.008 ) {
869869
utf8::downgrade($content, 1)
870870
or die(qq/Wide character in request message body\n/);
871871
}
@@ -1032,7 +1032,7 @@ my $unsafe_char = qr/[^A-Za-z0-9\-\._~]/;
10321032
sub _uri_escape {
10331033
my ($self, $str) = @_;
10341034
return "" if !defined $str;
1035-
if ( $] ge '5.008' ) {
1035+
if ( "$]" >= 5.008 ) {
10361036
utf8::encode($str);
10371037
}
10381038
else {
@@ -1189,7 +1189,7 @@ sub write {
11891189
@_ == 2 || die(q/Usage: $handle->write(buf)/ . "\n");
11901190
my ($self, $buf) = @_;
11911191

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

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

1524-
if ( $] ge '5.008' ) {
1524+
if ( "$]" >= 5.008 ) {
15251525
utf8::downgrade($data, 1)
15261526
or die(qq/Wide character in write_chunked_body()\n/);
15271527
}

cpan/Pod-Simple/lib/Pod/Simple.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ BEGIN {
3333
die "MANY_LINES is too small (", MANY_LINES(), ")!\nAborting";
3434
}
3535
if(defined &UNICODE) { }
36-
elsif($] >= 5.008) { *UNICODE = sub() {1} }
36+
elsif("$]" >= 5.008) { *UNICODE = sub() {1} }
3737
else { *UNICODE = sub() {''} }
3838
}
3939
if(DEBUG > 2) {
@@ -42,7 +42,7 @@ if(DEBUG > 2) {
4242
}
4343

4444
# The NO BREAK SPACE and SOFT HYHPEN are used in several submodules.
45-
if ($] ge 5.007_003) { # On sufficiently modern Perls we can handle any
45+
if ("$]" >= 5.007_003) { # On sufficiently modern Perls we can handle any
4646
# character set
4747
$Pod::Simple::nbsp = chr utf8::unicode_to_native(0xA0);
4848
$Pod::Simple::shy = chr utf8::unicode_to_native(0xAD);

cpan/Pod-Simple/lib/Pod/Simple/BlackBox.pm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ sub my_qr ($$) {
3535
my ($input_re, $should_match) = @_;
3636
# XXX could have a third parameter $shouldnt_match for extra safety
3737

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

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

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

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

271271
my $copy;
272272

273273
no warnings 'utf8';
274274

275-
if ($] ge 5.007_003) {
275+
if ("$]" >= 5.007_003) {
276276
$copy = $line;
277277

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

291291
my $char_ord;
292292
my $needed; # How many continuation bytes to gobble up

cpan/Pod-Simple/lib/Pod/Simple/DumpAsXML.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ sub _handle_element_end {
6767
sub _xml_escape {
6868
foreach my $x (@_) {
6969
# Escape things very cautiously:
70-
if ($] ge 5.007_003) {
70+
if ("$]" >= 5.007_003) {
7171
$x =~ s/([^-\n\t !\#\$\%\(\)\*\+,\.\~\/\:\;=\?\@\[\\\]\^_\`\{\|\}abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789])/'&#'.(utf8::native_to_unicode(ord($1))).';'/eg;
7272
} else { # Is broken for non-ASCII platforms on early perls
7373
$x =~ s/([^-\n\t !\#\$\%\(\)\*\+,\.\~\/\:\;=\?\@\[\\\]\^_\`\{\|\}abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789])/'&#'.(ord($1)).';'/eg;

cpan/Pod-Simple/lib/Pod/Simple/HTML.pm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ sub section_name_tidy {
701701
$section =~ s/^\s+//;
702702
$section =~ s/\s+$//;
703703
$section =~ tr/ /_/;
704-
if ($] ge 5.006) {
704+
if ("$]" >= 5.006) {
705705
$section =~ s/[[:cntrl:][:^ascii:]]//g; # drop crazy characters
706706
} elsif ('A' eq chr(65)) { # But not on early EBCDIC
707707
$section =~ tr/\x00-\x1F\x80-\x9F//d;
@@ -724,7 +724,7 @@ sub general_url_escape {
724724
# A pretty conservative escaping, behoovey even for query components
725725
# of a URL (see RFC 2396)
726726

727-
if ($] ge 5.007_003) {
727+
if ("$]" >= 5.007_003) {
728728
$string =~ s/([^-_\.!~*()abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789])/sprintf('%%%02X',utf8::native_to_unicode(ord($1)))/eg;
729729
} else { # Is broken for non-ASCII platforms on early perls
730730
$string =~ s/([^-_\.!~*()abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789])/sprintf('%%%02X',ord($1))/eg;
@@ -862,7 +862,7 @@ sub esc { # a function.
862862
@_ = splice @_; # break aliasing
863863
} else {
864864
my $x = shift;
865-
if ($] ge 5.007_003) {
865+
if ("$]" >= 5.007_003) {
866866
$x =~ s/([^-\n\t !\#\$\%\(\)\*\+,\.\~\/\:\;=\?\@\[\\\]\^_\`\{\|\}abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789])/'&#'.(utf8::native_to_unicode(ord($1))).';'/eg;
867867
} else { # Is broken for non-ASCII platforms on early perls
868868
$x =~ s/([^-\n\t !\#\$\%\(\)\*\+,\.\~\/\:\;=\?\@\[\\\]\^_\`\{\|\}abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789])/'&#'.(ord($1)).';'/eg;
@@ -873,7 +873,7 @@ sub esc { # a function.
873873
foreach my $x (@_) {
874874
# Escape things very cautiously:
875875
if (defined $x) {
876-
if ($] ge 5.007_003) {
876+
if ("$]" >= 5.007_003) {
877877
$x =~ s/([^-\n\t !\#\$\%\(\)\*\+,\.\~\/\:\;=\?\@\[\\\]\^_\`\{\|\}abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789])/'&#'.(utf8::native_to_unicode(ord($1))).';'/eg
878878
} else { # Is broken for non-ASCII platforms on early perls
879879
$x =~ s/([^-\n\t !\#\$\%\(\)\*\+,\.\~\/\:\;=\?\@\[\\\]\^_\`\{\|\}abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789])/'&#'.(ord($1)).';'/eg

cpan/Pod-Simple/lib/Pod/Simple/RTF.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ sub to_uni ($) { # Convert native code point to Unicode
1818
my $x = shift;
1919

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

551551
sub esc_uni($) {
552-
use if $] le 5.006002, 'utf8';
552+
use if "$]" >= 5.006002, 'utf8';
553553

554554
my $x = shift;
555555

cpan/Pod-Simple/lib/Pod/Simple/XMLOutStream.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ sub _handle_element_end {
7676
sub _xml_escape {
7777
foreach my $x (@_) {
7878
# Escape things very cautiously:
79-
if ($] ge 5.007_003) {
79+
if ("$]" >= 5.007_003) {
8080
$x =~ s/([^-\n\t !\#\$\%\(\)\*\+,\.\~\/\:\;=\?\@\[\\\]\^_\`\{\|\}abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789])/'&#'.(utf8::native_to_unicode(ord($1))).';'/eg;
8181
} else { # Is broken for non-ASCII platforms on early perls
8282
$x =~ s/([^-\n\t !\#\$\%\(\)\*\+,\.\~\/\:\;=\?\@\[\\\]\^_\`\{\|\}abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789])/'&#'.(ord($1)).';'/eg;

0 commit comments

Comments
 (0)