mirror of
https://github.com/friendica/friendica
synced 2025-04-25 04:30:11 +00:00
Refine BBCode::expandTags regular expression
- Now requires the tag to be preceded by either a non-word character or a start of a line - Added corresponding tests
This commit is contained in:
parent
5a93bb6eff
commit
8e99b7f775
2 changed files with 31 additions and 2 deletions
|
@ -75,6 +75,7 @@ class BBCodeTest extends MockedTest
|
|||
->andReturn($baseUrlMock);
|
||||
$baseUrlMock->shouldReceive('getHostname')->withNoArgs()->andReturn('friendica.local');
|
||||
$baseUrlMock->shouldReceive('getUrlPath')->withNoArgs()->andReturn('');
|
||||
$baseUrlMock->shouldReceive('__toString')->withNoArgs()->andReturn('friendica.local');
|
||||
|
||||
$config = \HTMLPurifier_HTML5Config::createDefault();
|
||||
$config->set('HTML.Doctype', 'HTML5');
|
||||
|
@ -339,4 +340,31 @@ class BBCodeTest extends MockedTest
|
|||
|
||||
self::assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function dataExpandTags()
|
||||
{
|
||||
return [
|
||||
'bug-10692-non-word' => [
|
||||
'[url=https://github.com/friendica/friendica/blob/2021.09-rc/src/Util/Logger/StreamLogger.php#L160]https://github.com/friendica/friendica/blob/2021.09-rc/src/Util/Logger/StreamLogger.php#L160[/url]',
|
||||
'[url=https://github.com/friendica/friendica/blob/2021.09-rc/src/Util/Logger/StreamLogger.php#L160]https://github.com/friendica/friendica/blob/2021.09-rc/src/Util/Logger/StreamLogger.php#L160[/url]',
|
||||
],
|
||||
'bug-10692-start-line' => [
|
||||
'#[url=https://friendica.local/search?tag=L160]L160[/url]',
|
||||
'#L160',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataExpandTags
|
||||
*
|
||||
* @param string $expected Expected BBCode output
|
||||
* @param string $text Input text
|
||||
*/
|
||||
public function testExpandTags(string $expected, string $text)
|
||||
{
|
||||
$actual = BBCode::expandTags($text);
|
||||
|
||||
self::assertEquals($expected, $actual);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue