Summary

In modules/price/src/Calculator.php, the check for a decimal point uses strpos($number, '.') != FALSE, which fails when the decimal point is at position 0 (e.g. '.5'). In that case strpos returns 0, and 0 != FALSE is false, so the decimal point is not detected.

Steps to reproduce

  1. Call Calculator::trim('.5') or any string where the decimal point is at index 0.
  2. Observe that trailing zeros are not stripped because the decimal point is not recognized.

Proposed solution

Replace the loose comparison with either:

  • strpos($number, '.') !== false, or
  • str_contains($number, '.') (PHP 8+).

Impact

This is a common PHP pitfall: when checking for substring presence, use strict comparison with false or str_contains() in PHP 8+.

Issue fork commerce-3579797

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

super_romeo created an issue. See original summary.

tbkot made their first commit to this issue’s fork.

tbkot’s picture

Status: Active » Needs review
super_romeo’s picture

Looks good.

jsacksick made their first commit to this issue’s fork.

  • jsacksick committed ea0e8268 on 3.x authored by tbkot
    fix: #3579797 Fix strpos check for decimal point in Calculator::trim()...
jsacksick’s picture

Status: Needs review » Fixed

Looks good! Merged thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.