Project

General

Profile

Actions

Bug #93890

closed

Move email check in LegacyLinkNotationConverter to the end

Added by Thomas Löffler about 3 years ago. Updated almost 3 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
-
Target version:
-
Start date:
2021-04-09
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
10
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

Problem

On a page with many links the check validEmail() in \TYPO3\CMS\Core\LinkHandling\LegacyLinkNotationConverter (line 74) takes many server resources.
The check for validEmail is at the beginning and mostly the link parameters are e.g. page UIDs (integer values).
So, the check will call some libraries and checks that will cost many resources.

Log output from typo3.org:

[09-Apr-2021 11:40:52 Europe/Berlin] PHP 191. TYPO3\CMS\Core\LinkHandling\LegacyLinkNotationConverter->resolve($linkParameter = '#transcript-1:02:56') /home/t3o-prod/ci/releases/26/private/typo3/sysext/core/Classes/LinkHandling/LinkService.php:87
[09-Apr-2021 11:40:52 Europe/Berlin] PHP 192. TYPO3\CMS\Core\Utility\GeneralUtility::validEmail($email = '') /home/t3o-prod/ci/releases/26/private/typo3/sysext/core/Classes/LinkHandling/LegacyLinkNotationConverter.php:74
[09-Apr-2021 11:40:52 Europe/Berlin] PHP 193. Egulias\EmailValidator\EmailValidator->isValid($email = '', $emailValidation = class Egulias\EmailValidator\Validation\RFCValidation { private $parser = class Egulias\EmailValidator\EmailParser { protected $warnings = [...]; protected $domainPart = ''; protected $localPart = ''; protected $lexer = class Egulias\EmailValidator\EmailLexer { ... }; protected $localPartParser = class Egulias\EmailValidator\Parser\LocalPart { ... }; protected $domainPartParser = class Egulias\EmailValidator\Parser\DomainPart { ... } }; private $warnings = []; private $error = NULL }) /home/t3o-prod/ci/releases/26/private/typo3/sysext/core/Classes/Utility/GeneralUtility.php:856
[09-Apr-2021 11:40:52 Europe/Berlin] PHP 194. Egulias\EmailValidator\Validation\RFCValidation->isValid($email = '', $emailLexer = class Egulias\EmailValidator\EmailLexer { protected $charValue = ['(' => 49, ')' => 261, '<' => 272, '>' => 273, '[' => 262, ']' => 263, ':' => 265, ';' => 275, '@' => 64, '\' => 92, '/' => 278, ',' => 274, '.' => 46, '\'' => 39, '`' => 96, '"' => 34, '-' => 264, '::' => 26' => 269, '67, '    ' => 268, '
' => 270, '
' => 301, 'IPv6' => 271, '{' => 276, '}' => 277, '' => NULL, '\0' => 0]; protected $hasInvalidTokens = FALSE; protected $previous = ['value' => '', 'type' => NULL, 'position' => 0]; public $token = ['value' => '', 'type' => NULL, 'position' => 0]; public $lookahead = NULL; private ${Doctrine\Common\Lexer\AbstractLexer}input = ''; private ${Doctrine\Common\Lexer\AbstractLexer}tokens = []; private ${Doctrine\Common\Lexer\AbstractLexer}position = 0; private ${Doctrine\Common\Lexer\AbstractLexer}peek = 0; private ${Doctrine\Common\Lexer\AbstractLexer}regex = '/([a-zA-Z_]+[46]?)|([^\\x00-\\x7F])|([0-9]+)|(\\r\\n)|(::)|(\\s+?)|(.)|[\\xA0-\\xff]+/iu' }) /home/t3o-prod/ci/releases/26/vendor/egulias/email-validator/src/EmailValidator.php:37
[09-Apr-2021 11:40:52 Europe/Berlin] PHP 195. Egulias\EmailValidator\EmailParser->parse($str = '') /home/t3o-prod/ci/releases/26/vendor/egulias/email-validator/src/Validation/RFCValidation.php:30
[09-Apr-2021 11:40:52 Europe/Berlin] PHP 196. Egulias\EmailValidator\Parser\DomainPart->parse($domainPart = '') /home/t3o-prod/ci/releases/26/vendor/egulias/email-validator/src/EmailParser.php:70
[09-Apr-2021 11:40:52 Europe/Berlin] PHP 197. Egulias\EmailValidator\Parser\DomainPart->performDomainStartChecks() /home/t3o-prod/ci/releases/26/vendor/egulias/email-validator/src/Parser/DomainPart.php:49
[09-Apr-2021 11:40:52 Europe/Berlin] PHP 198. Egulias\EmailValidator\Parser\DomainPart->checkEmptyDomain() /home/t3o-prod/ci/releases/26/vendor/egulias/email-validator/src/Parser/DomainPart.php:74

Solution

Move the check for a validEmail() to the end and all checks for string comparisons like strpos() to the begin.
It takes less resources checking if it's a page UID or anchors. The check for email address should be at the end.


Related issues 2 (0 open2 closed)

Related to TYPO3 Core - Bug #92531: Email with php method as string is a valid addressClosedGeorg Ringer2020-10-06

Actions
Related to TYPO3 Core - Bug #95042: email validation makes link generation unnecessary costlyClosed2021-08-31

Actions
Actions #1

Updated by Mathias Brodala about 3 years ago

  • Related to Bug #92531: Email with php method as string is a valid address added
Actions #2

Updated by Georg Ringer about 3 years ago

  • Status changed from New to Needs Feedback

problem is that a colon : is technically valid inside an email address. So the check strpos($linkParameter, ':') would change the behavior

Actions #3

Updated by Thomas Löffler about 3 years ago

But an @ is technical required for an email and could be checked before validEmail() starts.

Actions #4

Updated by Thomas Löffler about 3 years ago

Also you can check if it's a number (page UID) or a section (starts with #) before.

Actions #5

Updated by Gerrit Code Review almost 3 years ago

  • Status changed from Needs Feedback to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/68879

Actions #6

Updated by Gerrit Code Review almost 3 years ago

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/68879

Actions #7

Updated by Gerrit Code Review almost 3 years ago

Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/68879

Actions #8

Updated by Gerrit Code Review almost 3 years ago

Patch set 4 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/68879

Actions #9

Updated by Gerrit Code Review almost 3 years ago

Patch set 5 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/68879

Actions #10

Updated by Gerrit Code Review almost 3 years ago

Patch set 6 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/68879

Actions #11

Updated by Thomas Löffler almost 3 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
Actions #12

Updated by Benni Mack almost 3 years ago

  • Status changed from Resolved to Closed
Actions #13

Updated by Christian Kuhn over 2 years ago

  • Related to Bug #95042: email validation makes link generation unnecessary costly added
Actions

Also available in: Atom PDF