Skip to content

Commit

Permalink
Merge pull request #17 from XetaIO/fix-start-sentence
Browse files Browse the repository at this point in the history
Fix @mention at start of sentence
  • Loading branch information
Xety authored Aug 3, 2020
2 parents 803c32e + 904ec34 commit cd3e752
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ composer.phar
composer.lock
tests/vendor/coverage
tests/vendor/temp/database.sqlite
.phpunit.result.cache
4 changes: 2 additions & 2 deletions src/Parser/MentionParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class MentionParser extends Configurator
'mention' => true,
'notify' => true,
'character' => '@',
'regex' => '/\s({character}{pattern}{rules})/',
'regex' => '/({character}{pattern}{rules})/',
'regex_replacement' => [
'{character}' => '@',
'{pattern}' => '[A-Za-z0-9]',
Expand Down Expand Up @@ -91,7 +91,7 @@ protected function replace(array $match): string

$link = $route . $mention;

return " [{$character}{$mention}]($link)";
return "[{$character}{$mention}]($link)";
}

/**
Expand Down
17 changes: 16 additions & 1 deletion tests/Parser/MentionParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,21 @@ public function testParseWithLargestMentions()
$this->assertSame($output, $result);
}

/**
* testParseWithMentionsAtStart method
*
* @return void
*/
public function testParseWithMentionsAtStart()
{
$input = '@Admin crepu rhoncus id velit @adm sit amet @administrator.';
$output = '[@Admin](/users/profile/@Admin) crepu rhoncus id velit @adm sit amet @administrator.';

$this->parser->setOption('regex', '/({character}{pattern}{rules})/');
$result = $this->parser->parse($input);
$this->assertSame($output, $result);
}

/**
* testParseWithoutMention method
*
Expand All @@ -121,7 +136,7 @@ public function testParseWithoutMention()
public function testParseWithFakeMentionsAndWithoutMentions()
{
$input = 'Lorem ipsu @admin crepu @thisuserdoesntexist but this one @member yes. Also this blabla@admin is a non-normal mention.';
$output = 'Lorem ipsu [@Admin](/users/profile/@Admin) crepu @thisuserdoesntexist but this one [@Member](/users/profile/@Member) yes. Also this blabla@admin is a non-normal mention.';
$output = 'Lorem ipsu [@Admin](/users/profile/@Admin) crepu @thisuserdoesntexist but this one [@Member](/users/profile/@Member) yes. Also this blabla[@Admin](/users/profile/@Admin) is a non-normal mention.';

$this->parser->setOption('mention', false);
$result = $this->parser->parse($input);
Expand Down
2 changes: 1 addition & 1 deletion tests/vendor/Parser/CustomParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ protected function replace(array $match): string

$link = $route . $mention;

return " <a class=\"link\" href=\"{$link}\">{$character}{$mention}</a>";
return "<a class=\"link\" href=\"{$link}\">{$character}{$mention}</a>";
}
}

0 comments on commit cd3e752

Please sign in to comment.