Skip to content

fix(ui): allow negative values in validate-number-range (#40818)#40835

Open
lbajsarowicz wants to merge 1 commit into
magento:2.4-developfrom
lbajsarowicz:fix/40818-validate-number-range-negatives
Open

fix(ui): allow negative values in validate-number-range (#40818)#40835
lbajsarowicz wants to merge 1 commit into
magento:2.4-developfrom
lbajsarowicz:fix/40818-validate-number-range-negatives

Conversation

@lbajsarowicz
Copy link
Copy Markdown
Contributor

Description

ACP2E-3867 added a numeric pre-check /^(?:\d+\.?\d*|\.\d+)$/ to
validate-number-range. The regex rejects any leading minus sign, so UI
components declaring a range like validate-number-range -99-10000 reject
legitimate negative inputs even though the range explicitly allows them.

The dataAttrRange regex on the very next line already accepts -? on
both bounds, so the upstream short-circuit was the only blocker. Allow
an optional leading - in the numeric pre-check.

Updated the jasmine spec to reflect the correct expected behaviour for
negative ranges (the existing test was asserting the buggy result) and
added coverage for the mixed-sign range case from the issue.

Fixes #40818

Fixed Issues

Manual testing scenarios

Declare a UI component field with:

<item name="validate-number-range" xsi:type="string">-99-10000</item>

Before: any negative input fails with The value is not within the specified range.
After: negatives within the range pass; values outside the range still fail.

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All automated tests passed successfully (rules.test.js coverage extended)
  • Changes to the codebase comply with technical guidelines

ACP2E-3867 added a pre-check `/^(?:\d+\.?\d*|\.\d+)$/` to the
validate-number-range rule. The regex rejected any leading minus sign,
so UI components that declared a range like `validate-number-range -99-10000`
broke for legitimate negative inputs even though the range explicitly
allowed them. The dataAttrRange regex on the very next line already
supports `-?` on both bounds, so the upstream short-circuit was the
only blocker.

Allow an optional leading `-` in the numeric pre-check. Update the
jasmine spec to reflect the correct expected behaviour for negative
ranges (previously the spec was asserting the buggy result) and add
coverage for the mixed-sign range case from magento#40818.

Fixes magento#40818
@m2-assistant
Copy link
Copy Markdown

m2-assistant Bot commented May 25, 2026

Hi @lbajsarowicz. Thank you for your contribution!
Here are some useful tips on how you can test your changes using Magento test environment.
❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names.

Allowed build names are:
  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here
ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review.


For more details, review the Code Contributions documentation.
Join Magento Community Engineering Slack and ask your questions in #github channel.

@lbajsarowicz
Copy link
Copy Markdown
Contributor Author

@magento run all tests

@engcom-Hotel engcom-Hotel added the Priority: P2 A defect with this priority could have functionality issues which are not to expectations. label May 26, 2026
@github-project-automation github-project-automation Bot moved this to Pending Review in Pull Requests Dashboard May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: pending review

Projects

Status: Pending Review

Development

Successfully merging this pull request may close these issues.

UI components validate-number-range validation rule no longer allowing negative values

2 participants