Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix string comparisons with $] to use numeric comparison instead #177

Merged
merged 1 commit into from
Jan 3, 2025

Conversation

book
Copy link
Contributor

@book book commented Dec 12, 2024

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";

Note that, because some of the files do a use integer, the numeric
comparisons with $] a no integer needs to be done in a lexical scope
around the comparison, to avoid truncation to integers, which spoils
the comparisons. Hence the ugly do { no integer ; ... } in some places.

@book book force-pushed the fix-version-string-comparisons branch from 23e1e60 to d01de45 Compare December 30, 2024 11:09
@@ -551,7 +551,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 do { no integer; "$]" >= 5.006002 }, 'utf8';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not equivalent to the previous line, but I think what you have here now is correct, as surely one does not mean to use utf8 on a version where it does not exist! :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow, that's a bug I introduced myself! This >= should indeed be a <=. Will push a fixed commit.

Thanks for catching this!

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";

Note that, because some of the files do a `use integer`, the numeric
comparisons with $] a `no integer` needs to be done in a lexical scope
around the comparison, to avoid truncation to integers, which spoils
the comparisons. Hence the ugly `do { no integer ; ... }` in some places.
@book book force-pushed the fix-version-string-comparisons branch from d01de45 to a24d9e1 Compare December 31, 2024 10:52
@khwilliamson khwilliamson merged commit 5fa9972 into perl-pod:master Jan 3, 2025
18 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants