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

Fix labels length check #278

Merged
merged 3 commits into from
Dec 29, 2020
Merged

Conversation

vajexal
Copy link

@vajexal vajexal commented Dec 8, 2020

  • pass label instead of previous token to checkLabelLength
    method because lexer parses digits and unicode chars as different tokens
var_dump(
    (new EmailValidator())->isValid(sprintf('example@%s.com', str_repeat('a4t', 50)), new NoRFCWarningsValidation())
);

// true but domain part is invalid
  • convert idn to ascii to check label length of unicode domains
var_dump(
    (new EmailValidator())->isValid(sprintf('example@%s.com', str_repeat('ъ', 60)), new NoRFCWarningsValidation())
);

// true but domain part is invalid

Copy link
Owner

@egulias egulias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @vajexal, thanks for your PR.
I've left some comment for you.

private function isLabelTooLong($label)
{
if (preg_match('/[^\x00-\x7F]/', $label)) {
$label = idn_to_ascii($label, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46, $idnaInfo);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are overriding the original $label from the parameters, please use another variable, i.e $asciiLabel.

if (preg_match('/[^\x00-\x7F]/', $label)) {
$label = idn_to_ascii($label, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46, $idnaInfo);

if (!$label) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could remove the if and directly return return (bool) ($idnaInfo['errors'] | IDNA_ERROR_LABEL_TOO_LONG) , label has passed the length test already so testing again in line 422 wouldn't be needed.

@vajexal vajexal requested a review from egulias December 24, 2020 10:21
@egulias
Copy link
Owner

egulias commented Dec 28, 2020

Good job @vajexal ! Thanks for contributing.
I'll merge shortly.

'example@toolonglocalparttoolonglocalparttoolonglocalparttoolonglocalparttoolonglocalparttoolonglocal'.
'parttoolonglocalparttoolonglocalparttoolonglocalparttoolonglocalparttoolonglocalparttoolonglocalpart'.
'toolonglocalparttoolonglocalparttoolonglocalparttoolonglocalpar'
],
[
[LabelTooLong::CODE,],
sprintf('example@%s.com', str_repeat('ъ', 60)),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vajexal while porting to v3, why this should rise the warning? it is a 60 char label long

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because if we convert label to idn, it's length will be > 63

var_dump(idn_to_ascii(str_repeat('ъ', 60), IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46, $idnaInfo), $idnaInfo);
// bool(false)
// array(3) {
//   ["result"]=> string(66) "xn--z1aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
//   ["isTransitionalDifferent"]=> bool(false)
//   ["errors"]=> int(2)
// }

egulias added a commit that referenced this pull request Dec 28, 2020
@egulias
Copy link
Owner

egulias commented Dec 29, 2020

Merging in order to release v3. Can you answer the question anyway please?

@egulias egulias merged commit 0dbf5d7 into egulias:master Dec 29, 2020
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

Successfully merging this pull request may close these issues.

2 participants