Commit 4bdc929b authored by Morton Jonuschat's avatar Morton Jonuschat Committed by Alexander Opitz
Browse files

[BUGFIX] Make getFirstTag() return empty string for input without tag

getFirstTag() didn't take into account that strpos() returns FALSE when
the needle isn't found.

Resolves: #69318
Releases: master
Change-Id: Ie530db9cbed92fa11199852cc0aec77024354814
Reviewed-on: http://review.typo3.org/42898

Reviewed-by: default avatarMichael Oehlhof <typo3@oehlhof.de>
Tested-by: default avatarMichael Oehlhof <typo3@oehlhof.de>
Reviewed-by: Alexander Opitz's avatarAlexander Opitz <opitz.alexander@googlemail.com>
Tested-by: Alexander Opitz's avatarAlexander Opitz <opitz.alexander@googlemail.com>
parent 61d023cd
......@@ -362,8 +362,8 @@ class HtmlParser {
*/
public function getFirstTag($str) {
// First:
$endLen = strpos($str, '>') + 1;
return substr($str, 0, $endLen);
$endLen = strpos($str, '>');
return $endLen !== FALSE ? substr($str, 0, $endLen + 1) : '';
}
/**
......
......@@ -343,8 +343,10 @@ class HtmlParserTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
*/
public function getFirstTagDataProvider() {
return array(
array('<body><span></span></body>',
'<body>'),
array('<body><span></span></body>', '<body>'),
array('<span>Wrapper<div>Some content</div></span>', '<span>'),
array('Something before<span>Wrapper<div>Some content</div></span>Something after', 'Something before<span>'),
array('Something without tag', '')
);
}
......@@ -429,4 +431,5 @@ class HtmlParserTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
public function removeFirstAndLastTag($str, $expectedResult) {
$this->assertEquals($expectedResult, $this->subject->removeFirstAndLastTag($str));
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment