User tests: Successful: Unsuccessful:
When parameter with empty value is passed to the JInput and filter is INT, JInput will return 0 instead of default value. There is similar problem with other fitlers too as isset will consider "" as set, and afterwards fitlers will perform typecasting on it.
Fixes #5851
Labels |
Added:
?
|
Category | ⇒ | Libraries |
Rel_Number | ⇒ | 5851 | |
Relation Type | ⇒ | Pull Request for |
I agree. I consider this expected behaviour.
I am closing this as expected behaviour based on the comments by the two PLT members above
Status | Pending | ⇒ | Expected Behaviour |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2015-01-21 19:15:26 |
Closed_By | ⇒ | brianteeman |
Closed_Date | 2015-01-21 19:15:26 | ⇒ | 2015-01-21 19:15:27 |
Please consider reopening this:
If 0 is expected behaviour here then function is flawed in different way - when variable is not set in url at all, you don't get 0, you get default value. Variable without value should be treated in the same way as variable that is not present at all.
Underlying problem is php assigning empty string instead of null to the parameters without value http://php.net/manual/en/reserved.variables.get.php#98419
Your are mixing things:
If it is not set in the url and we follow your thinking, then JInput->get('notsetvar', 'whatever', 'int') will return "whatever". That isn't an int nor nothing, so it couldn't be more wrong.
If you need to check, if something is part of the url you can use the JUri class. The purpose of the JInput class is to protect before injecting something that we will not have gotten via the request.
I agree with Robert that JInput->getInt should always return an int. Your default value null
is basically an invalid default value for that method and gets correctly converted to 0.
When variable is not present in the url JInput->get('notsetvar', 'whatever', 'int') will indeed return 'whatever'. Please check by yourself.
But you get different result when url has this variable, just without any value. Hope this makes sense, what I'm talking about is that with the abouve code you get "whatever" when url is index.php?abc=1 and you get 0 when url is index.php?whatever=&abc=1.
I was wrongly trying to change this second behaviour while it seems now it is the first instance that needs fixing.
I expect to get an int back when I filter on int, don't see the problem here.