-
Notifications
You must be signed in to change notification settings - Fork 7.9k
New FILTER_VALIDATE_DOMAIN and better RFC conformance for FILTER_VALIDATE_URL #826
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
--TEST-- | ||
filter_var() and FILTER_VALIDATE_DOMAIN | ||
--SKIPIF-- | ||
<?php if (!extension_loaded("filter")) die("skip"); ?> | ||
--FILE-- | ||
<?php | ||
|
||
$values = Array( | ||
'example.com', | ||
'www.thelongestdomainnameintheworldandthensomeandthensomemoreandmore.com', | ||
'toolongtoolongtoolongtoolongtoolongtoolongtoolongtoolongtoolongtoolong.com', | ||
'eauBcFReEmjLcoZwI0RuONNnwU4H9r151juCaqTI5VeIP5jcYIqhx1lh5vV00l2rTs6y7hOp7rYw42QZiq6VIzjcYrRm8gFRMk9U9Wi1grL8Mr5kLVloYLthHgyA94QK3SaXCATklxgo6XvcbXIqAGG7U0KxTr8hJJU1p2ZQ2mXHmp4DhYP8N9SRuEKzaCPcSIcW7uj21jZqBigsLsNAXEzU8SPXZjmVQVtwQATPWeWyGW4GuJhjP4Q8o0.com', | ||
'kDTvHt1PPDgX5EiP2MwiXjcoWNOhhTuOVAUWJ3TmpBYCC9QoJV114LMYrV3Zl58.kDTvHt1PPDgX5EiP2MwiXjcoWNOhhTuOVAUWJ3TmpBYCC9QoJV114LMYrV3Zl58.kDTvHt1PPDgX5EiP2MwiXjcoWNOhhTuOVAUWJ3TmpBYCC9QoJV114LMYrV3Zl58.CQ1oT5Uq3jJt6Uhy3VH9u3Gi5YhfZCvZVKgLlaXNFhVKB1zJxvunR7SJa.com.', | ||
'cont-ains.h-yph-en-s.com', | ||
'..com', | ||
'ab..cc.dd', | ||
'a.-bc.com', | ||
'ab.cd-.com', | ||
'-.abc.com', | ||
'abc.-.abc.com', | ||
'underscore_.example.com', | ||
'', | ||
-1, | ||
array(), | ||
'\r\n', | ||
); | ||
foreach ($values as $value) { | ||
var_dump(filter_var($value, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)); | ||
} | ||
|
||
var_dump(filter_var('_example.com', FILTER_VALIDATE_DOMAIN)); | ||
var_dump(filter_var('_example.com', FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)); | ||
var_dump(filter_var('test_.example.com', FILTER_VALIDATE_DOMAIN)); | ||
var_dump(filter_var('test_.example.com', FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)); | ||
var_dump(filter_var('te_st.example.com', FILTER_VALIDATE_DOMAIN)); | ||
var_dump(filter_var('te_st.example.com', FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)); | ||
var_dump(filter_var('test._example.com', FILTER_VALIDATE_DOMAIN)); | ||
var_dump(filter_var('test._example.com', FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)); | ||
|
||
echo "Done\n"; | ||
?> | ||
--EXPECT-- | ||
string(11) "example.com" | ||
string(71) "www.thelongestdomainnameintheworldandthensomeandthensomemoreandmore.com" | ||
bool(false) | ||
bool(false) | ||
string(254) "kDTvHt1PPDgX5EiP2MwiXjcoWNOhhTuOVAUWJ3TmpBYCC9QoJV114LMYrV3Zl58.kDTvHt1PPDgX5EiP2MwiXjcoWNOhhTuOVAUWJ3TmpBYCC9QoJV114LMYrV3Zl58.kDTvHt1PPDgX5EiP2MwiXjcoWNOhhTuOVAUWJ3TmpBYCC9QoJV114LMYrV3Zl58.CQ1oT5Uq3jJt6Uhy3VH9u3Gi5YhfZCvZVKgLlaXNFhVKB1zJxvunR7SJa.com." | ||
string(24) "cont-ains.h-yph-en-s.com" | ||
bool(false) | ||
bool(false) | ||
bool(false) | ||
bool(false) | ||
bool(false) | ||
bool(false) | ||
bool(false) | ||
bool(false) | ||
bool(false) | ||
bool(false) | ||
bool(false) | ||
string(12) "_example.com" | ||
bool(false) | ||
string(17) "test_.example.com" | ||
bool(false) | ||
string(17) "te_st.example.com" | ||
bool(false) | ||
string(17) "test._example.com" | ||
bool(false) | ||
Done |
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.
Why start the label length at 1 if you haven't read any characters from the string yet?
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.
Because the length incrementation occurs after the length check (see https://github.com/dunglas/php-src/blob/validate_url_length/ext/filter/logical_filters.c#L497-L501).
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.
That's exactly my point, your invariant choice for
i
is just unusual; it would be more logical to define it as the number of characters since the last period ... I know, nitpicking :PThere 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.
@datibbaw I'm ok to initialize
i
as0
and move the increment operation before the check (it's your point right?) if it's already done like that in other part of the code base. Anyway, doing it like I've done avoids one unnecessary increment operation when the label is > 63 characters.Number of
++
operations when label is 64 chars:current implementation: 63
your suggestion: 64
It's really micro-optimization with no impact in real uses case but... :-)