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

Gte/Lte/Lt/Gt incorrectly treat strings as numeric? #40308

Closed
sparxooo opened this issue Jan 8, 2022 · 4 comments
Closed

Gte/Lte/Lt/Gt incorrectly treat strings as numeric? #40308

sparxooo opened this issue Jan 8, 2022 · 4 comments

Comments

@sparxooo
Copy link

sparxooo commented Jan 8, 2022

  • Laravel Version: 8.75.
  • PHP Version: 8.1.1

Description:

When validating strings using Gte/Gt/Lte/Lt, as per the Laravel docs, it should count characters in strings, as per the size validator.

When validating "password" using rule "gte:8" it will fail
When validating "8" using rule "gte:8" it will pass
When validating "7" using rule "gte:8" it will fail
When validating "9" using rule "gte:8" it will pass

Size works correctly:

When validating "password" using rule "size:8" it will pass
When validating "8" using rule "size:8" it will fail

If i'm doing it wrong, I apologise!

Steps To Reproduce:

Validate a string with lte/lt/gt/gte to match lengths

@driesvints
Copy link
Member

Hi there,

Thanks for reporting but it looks like this is a question which can be asked on a support channel. Please only use this issue tracker for reporting bugs with the library itself. If you have a question on how to use functionality provided by this repo you can try one of the following channels:

However, this issue will not be locked and everyone is still free to discuss solutions to your problem!

Thanks.

@sparxooo
Copy link
Author

sparxooo commented Jan 8, 2022

Hi driesvints,

Either the documentation is wrong, or there is a bug.

Validation Rule GTE

Rule GTE
The field under validation must be greater than or equal to the given field. The two fields must be of the same type. Strings, numerics, arrays, and files are evaluated using the same conventions as the size rule.

The problem is that it does not evaluate it the same as the size rule. There is some more logic in the code before it uses the getSize function (and I believe part of the issue is that it checks the type of the parameter, which is always going to be a number, and so it never actually gets to calling getSize).

@sparxooo
Copy link
Author

sparxooo commented Jan 8, 2022

Furthermore to this issue, i've managed (finally! :) ) to set up PHP debugging, and i've stepped through the code:

I believe that Issue #33711 and #28174 have both contributed to this change in behaviour (and this was commented about in the latter!)

The docs should probably be changed to point out that you cannot use these operators (Gt/Gte/Lt/Lte) for string comparisons (at the very least, i've not tested other results). I can't see what i'm doing grossly incorrectly from the docs.

@sparxooo
Copy link
Author

sparxooo commented Jan 8, 2022

See PR for final change, I was incorrect in my initial reasoning.

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

No branches or pull requests

2 participants