Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly treat smileys with square parentheses at beginning of messages #7

Merged
merged 2 commits into from Apr 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Nickvergessen/TrimMessage/PhpbbBbcodes.php
Expand Up @@ -498,7 +498,7 @@ public function filter_bbcode_tag($bbcode_tag, $strip_information = true, $strip
protected function replace_square_brackets_in_smilies()
{
// Replace all [ that are inside of <> because they belong to smilies
if (utf8_strpos($this->message, '<'))
if (utf8_strpos($this->message, '<') !== false)
{
$this->bracket_replacement = '{' . md5($this->message) . '}';
while (utf8_strpos($this->message, $this->bracket_replacement) !== false)
Expand Down
16 changes: 16 additions & 0 deletions src/Nickvergessen/TrimMessage/Tests/TrimTest.php
Expand Up @@ -45,6 +45,10 @@ public function trim_message_data()
'message' => 'h<!-- s[geek] --><img src="{SMILIES_PATH}/icon_e_geek.gif" alt="[geek]" title="Geek" /><!-- s[geek] -->h<!-- s[geek] --><img src="{SMILIES_PATH}/icon_e_geek.gif" alt="[geek]" title="Geek" /><!-- s[geek] -->h',
'bbcode_uid' => '2sda49fx',
),
array(
'message' => '<!-- s[foo.bar] --><img src="{SMILIES_PATH}/icon_e_geek.gif" alt="[foo.bar]" title="Geek" /><!-- s[foo.bar] -->h<!-- s[foo.bar] --><img src="{SMILIES_PATH}/icon_e_geek.gif" alt="[foo.bar]" title="Geek" /><!-- s[foo.bar] -->h foo bar',
'bbcode_uid' => '2sda49fx',
),
);

$cases = array(
Expand Down Expand Up @@ -199,6 +203,18 @@ public function trim_message_data()
'message_set' => 6, 'length' => 4, 'trimmed' => true,
'expected' => 'foo[url:2sda49fx]https://github.com/nickvergessen/phpbb3-tools-trim-message[/url:2sda49fx]b [...]',
),

/**
* Breaking withing smiley with dot and square parentheses
*/
array(
'message_set' => 8, 'length' => 20, 'trimmed' => false,
'expected' => '<!-- s[foo.bar] --><img src="{SMILIES_PATH}/icon_e_geek.gif" alt="[foo.bar]" title="Geek" /><!-- s[foo.bar] -->h<!-- s[foo.bar] --><img src="{SMILIES_PATH}/icon_e_geek.gif" alt="[foo.bar]" title="Geek" /><!-- s[foo.bar] -->h foo bar',
),
array(
'message_set' => 8, 'length' => 10, 'trimmed' => true,
'expected' => '<!-- s[foo.bar] --><img src="{SMILIES_PATH}/icon_e_geek.gif" alt="[foo.bar]" title="Geek" /><!-- s[foo.bar] -->h [...]',
),
);

$test_cases = array();
Expand Down