Skip to content

Commit 8440144

Browse files
committed
[HTTP-Tiny] 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 e570b86 commit 8440144

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

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
}

0 commit comments

Comments
 (0)