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

[BUG]: Numericality allows spaces #16461

Closed
krazzer opened this issue Nov 5, 2023 · 4 comments
Closed

[BUG]: Numericality allows spaces #16461

krazzer opened this issue Nov 5, 2023 · 4 comments
Assignees
Labels
5.0 The issues we want to solve in the 5.0 release bug A bug report status: medium Medium

Comments

@krazzer
Copy link

krazzer commented Nov 5, 2023

Describe the bug
The Numericality allows spaces when validating

To Reproduce
Create a field with a Numericality validator. Type "1 " and it will pass

Expected behavior
I would expect this would not pass.

Details

  • Phalcon version: 5.4.0
  • PHP Version: 8.2

Additional context
I have a number field in my form, that eventually will be stored in the DB as a number. The input is validated using Numericality, because it must be a number. Something like "1 " or "1 1" passes with Numericality. And then I get an error from the DB because it's not a valid number. So then I would have to write extra logic for it to work.

@krazzer krazzer added bug A bug report status: unverified Unverified labels Nov 5, 2023
@niden
Copy link
Member

niden commented Nov 6, 2023

@krazzer From what I see in the code the validator removes the spaces from the input and then validates using regex. As such, what you see is correct but not desirable. The code that was added to the validator to remove spaces was because this validator was not working in certain locales.

I can make some modifications to now take into account spaces. The best candidate is to use ctype_digit but that does not take into account periods, so 123.45 will not validate as a number.

I am thinking the long term solution would be to change this validator and split it into a Digits one and then maybe have others that are more specific such as Int or Float.

Thoughts?

@niden niden self-assigned this Nov 6, 2023
@niden niden added status: medium Medium 5.0 The issues we want to solve in the 5.0 release and removed status: unverified Unverified labels Nov 6, 2023
@niden
Copy link
Member

niden commented Nov 6, 2023

@krazzer never mind. I figured out a way to make it work and take into account spaces

@niden niden mentioned this issue Nov 6, 2023
5 tasks
@niden
Copy link
Member

niden commented Nov 6, 2023

Resolved in #16462

@niden niden closed this as completed Nov 6, 2023
@niden
Copy link
Member

niden commented Nov 6, 2023

Thank you @krazzer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5.0 The issues we want to solve in the 5.0 release bug A bug report status: medium Medium
Projects
Status: Released
Development

No branches or pull requests

2 participants