Skip to content

Commit

Permalink
[BUGFIX] Correctly consider nested tags in frontend HTML parser
Browse files Browse the repository at this point in the history
Nested tags starting with the same literals, like `<s><span>...`
or `<a ...><abbr>...` are not correctly nested due to a flaw in
identifying proper start and end of HTML tags.

Resolves: #91194
Releases: master
Change-Id: I2029c8e01d66e5286790fd04a259153cd130c753
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/64409
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Oliver Hader <oliver.hader@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Susanne Moog <look@susi.dev>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Helmut Hummel <typo3@helhum.io>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Oliver Hader <oliver.hader@typo3.org>
Reviewed-by: Susanne Moog <look@susi.dev>
  • Loading branch information
jkphl authored and susannemoog committed May 8, 2020
1 parent ee06649 commit 03f5310
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 161 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3932,7 +3932,8 @@ public function _parseFunc($theValue, $conf)
// call this method recursively if found
if (strpos($data, '<') !== false && isset($conf['tags.']) && is_array($conf['tags.'])) {
foreach ($conf['tags.'] as $tag => $tagConfig) {
if (strpos($data, '<' . $tag) !== false) {
// only match tag `a` in `<a href"...">` but not in `<abbr>`
if (preg_match('#<' . $tag . '[\s/>]#', $data)) {
$data = $this->_parseFunc($data, $conf);
break;
}
Expand Down Expand Up @@ -7113,7 +7114,13 @@ protected function getContentLengthOfCurrentTag(string $theValue, int $pointer,
// Take care for nested tags
do {
$nextMatchingEndTagPosition = strpos($tempContent, $endTag);
$nextSameTypeTagPosition = strpos($tempContent, $startTag);
// only match tag `a` in `<a href"...">` but not in `<abbr>`
$nextSameTypeTagPosition = preg_match(
'#' . $startTag . '[\s/>]#',
$tempContent,
$nextSameStartTagMatches,
PREG_OFFSET_CAPTURE
) ? $nextSameStartTagMatches[0][1] : false;

// filter out nested tag contents to help getting the correct closing tag
if ($nextSameTypeTagPosition !== false && $nextSameTypeTagPosition < $nextMatchingEndTagPosition) {
Expand Down
Loading

0 comments on commit 03f5310

Please sign in to comment.