-
Notifications
You must be signed in to change notification settings - Fork 429
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
filter_var() should return non empty string only when it will not be sanitized #650
Merged
ondrejmirtes
merged 9 commits into
phpstan:master
from
devbanana:filter_var-should-return-non-empty-string
Aug 29, 2021
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
260d542
Add support for FILTER_VALIDATE_DOMAIN
devbanana 5742978
Only return non-empty-string if there is no chance of sanitization
devbanana c16a335
Add Scope type declaration
devbanana 5962964
Make boolean explicit in condition
devbanana b237ee3
Move bitmask to constant
devbanana 21f4c8a
Fix coding style
devbanana 3b55c95
Fix checking for Stringtype
devbanana 1961a37
Move check for StringType to calling condition
devbanana 015bc7b
Add test to ensure it only operates on string filters
devbanana File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem right. For example what do you want to happen for these types?
mixed
string|null
string
'1'
int
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're missing where $filterType is coming from. It's the type returned from
getFilterTypeMap()
, which only ever returnsBooleanType
,FloatType
,IntType
, orStringType
. So all I'm doing here is ensuring that we're only operating on filters that return strings. It's not verifying the type of the input itself, which isin $inputType
. See where I'm calling it in line 140.It's also why I felt OK using
instanceof StringType
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused. You're caling a method called
canStringBeSanitized
and if the input isn't a string, it returnstrue
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps I should move that check to the condition on line 139, or else rename the method. if I return false, then it'll return non-empty-string if something like this is done:
Since a string is being passed, but FILTER_VALIDATE_INT should return an int, not a string. So I only want to operate on filters that return strings. Let me move the check and see if that makes more sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I like this more, just make sure this case is also tested
filter_var('foo', FILTER_VALIDATE_INT);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, done.