mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-21 14:01:27 +00:00
Update lexer regex, fix mention regex and add more tests
This commit is contained in:
parent
36df0d8373
commit
778e83d398
2 changed files with 64 additions and 1 deletions
|
@ -162,7 +162,7 @@ abstract class Regex
|
|||
// look-ahead capture here and don't append $after when we return.
|
||||
$tmp['valid_mention_preceding_chars'] = '([^a-zA-Z0-9_!#\$%&*@@\/]|^|(?:^|[^a-z0-9_+~.-])RT:?)';
|
||||
|
||||
$re['valid_mentions_or_lists'] = '/'.$tmp['valid_mention_preceding_chars'].'(['.$tmp['at_signs'].'])([a-z0-9_\-.]{1,20})((\/[a-z][a-z0-9_\-]{0,24})?(?=(.*|$))(?:@[a-z0-9\.\-]+[a-z0-9]+)?)/i';
|
||||
$re['valid_mentions_or_lists'] = '/'.$tmp['valid_mention_preceding_chars'].'(['.$tmp['at_signs'].'])([\p{L}0-9_\-.]{1,20})((\/[a-z][a-z0-9_\-]{0,24})?(?=(.*|$))(?:@[a-z0-9\.\-]+[a-z0-9]+)?)/iu';
|
||||
|
||||
$re['valid_reply'] = '/^(?:['.$tmp['spaces'].'])*['.$tmp['at_signs'].']([a-z0-9_\-.]{1,20})(?=(.*|$))/iu';
|
||||
$re['end_mention_match'] = '/\A(?:['.$tmp['at_signs'].']|['.$tmp['latin_accents'].']|:\/\/)/iu';
|
||||
|
|
|
@ -175,4 +175,67 @@ class UsernameTest extends TestCase
|
|||
$this->assertEquals($expectedEntity, $entities);
|
||||
}
|
||||
|
||||
/** @test * */
|
||||
public function germanUmlatsAutolink()
|
||||
{
|
||||
$mentions = "@März and @königin and @Glück";
|
||||
$autolink = Autolink::create()->autolink($mentions);
|
||||
|
||||
$expectedAutolink = '<a class="u-url mention" href="https://pixelfed.dev/März" rel="external nofollow noopener" target="_blank">@März</a> and <a class="u-url mention" href="https://pixelfed.dev/königin" rel="external nofollow noopener" target="_blank">@königin</a> and <a class="u-url mention" href="https://pixelfed.dev/Glück" rel="external nofollow noopener" target="_blank">@Glück</a>';
|
||||
$this->assertEquals($expectedAutolink, $autolink);
|
||||
}
|
||||
|
||||
/** @test * */
|
||||
public function germanUmlatsExtractor()
|
||||
{
|
||||
$mentions = "@März and @königin and @Glück";
|
||||
$entities = Extractor::create()->extract($mentions);
|
||||
|
||||
$expectedEntity = [
|
||||
"hashtags" => [],
|
||||
"urls" => [],
|
||||
"mentions" => [
|
||||
"märz",
|
||||
"königin",
|
||||
"glück",
|
||||
],
|
||||
"replyto" => null,
|
||||
"hashtags_with_indices" => [],
|
||||
"urls_with_indices" => [],
|
||||
"mentions_with_indices" => [
|
||||
[
|
||||
"screen_name" => "März",
|
||||
"indices" => [
|
||||
0,
|
||||
5,
|
||||
],
|
||||
],
|
||||
[
|
||||
"screen_name" => "königin",
|
||||
"indices" => [
|
||||
10,
|
||||
18,
|
||||
],
|
||||
],
|
||||
[
|
||||
"screen_name" => "Glück",
|
||||
"indices" => [
|
||||
23,
|
||||
29,
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
$this->assertEquals($expectedEntity, $entities);
|
||||
}
|
||||
|
||||
/** @test * */
|
||||
public function germanUmlatsWebfingerAutolink()
|
||||
{
|
||||
$mentions = "hello @märz@example.org!";
|
||||
$autolink = Autolink::create()->autolink($mentions);
|
||||
|
||||
$expectedAutolink = 'hello <a class="u-url list-slug" href="https://pixelfed.dev/@märz@example.org" rel="external nofollow noopener" target="_blank">@märz@example.org</a>!';
|
||||
$this->assertEquals($expectedAutolink, $autolink);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue