Support smart quotes in mentions format

This commit is contained in:
SychO9 2021-05-24 21:49:31 +01:00
parent a311edf106
commit cc62044e6f
3 changed files with 34 additions and 3 deletions

View File

@ -76,7 +76,7 @@ export default function addComposerAutocomplete() {
if (absMentionStart) {
typed = lastChunk.substring(relMentionStart).toLowerCase();
matchTyped = typed.match(/^"((?:(?!"#).)+)$/);
matchTyped = typed.match(/^["|“]((?:(?!"#).)+)$/);
typed = (matchTyped && matchTyped[1]) || typed;
const makeSuggestion = function(user, replacement, content, className = '') {

View File

@ -58,7 +58,7 @@ class ConfigureMentions
$tag->filterChain->prepend([static::class, 'addUserId'])
->setJS('function(tag) { return flarum.extensions["flarum-mentions"].filterUserMentions(tag); }');
$config->Preg->match('/\B@"(?<displayname>((?!"#[a-z]{0,3}[0-9]+).)+)"#(?<id>[0-9]+)\b/', $tagName);
$config->Preg->match('/\B@["|“](?<displayname>((?!"#[a-z]{0,3}[0-9]+).)+)["|”]#(?<id>[0-9]+)\b/', $tagName);
$config->Preg->match('/\B@(?<username>[a-z0-9_-]+)(?!#)/i', $tagName);
}
@ -114,7 +114,7 @@ class ConfigureMentions
->prepend([static::class, 'addPostId'])
->setJS('function(tag) { return flarum.extensions["flarum-mentions"].filterPostMentions(tag); }');
$config->Preg->match('/\B@"(?<displayname>((?!"#[a-z]{0,3}[0-9]+).)+)"#p(?<id>[0-9]+)\b/', $tagName);
$config->Preg->match('/\B@["|“](?<displayname>((?!"#[a-z]{0,3}[0-9]+).)+)["|”]#p(?<id>[0-9]+)\b/', $tagName);
}
/**

View File

@ -156,6 +156,37 @@ class UserMentionsTest extends TestCase
$this->assertNotNull(CommentPost::find($response['data']['id'])->mentionsUsers->find(3));
}
/**
* @test
*/
public function mentioning_a_valid_user_with_new_format_with_smart_quotes_works()
{
$response = $this->send(
$this->request('POST', '/api/posts', [
'authenticatedAs' => 1,
'json' => [
'data' => [
'attributes' => [
'content' => '@“POTATO$”#3',
],
'relationships' => [
'discussion' => ['data' => ['id' => 2]],
],
],
],
])
);
$this->assertEquals(201, $response->getStatusCode());
$response = json_decode($response->getBody(), true);
$this->assertStringContainsString('@POTATO$', $response['data']['attributes']['contentHtml']);
$this->assertStringContainsString('@"POTATO$"#3', $response['data']['attributes']['content']);
$this->assertStringContainsString('UserMention', $response['data']['attributes']['contentHtml']);
$this->assertNotNull(CommentPost::find($response['data']['id'])->mentionsUsers->find(3));
}
/**
* @test
*/