From 8d7be51996885fd160e95c7766980ef4031931dd Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Thu, 28 May 2015 04:25:09 -0400
Subject: [PATCH] Fix replacing :$, :-$, O:) and O:-) with emoticons (#1490408, #1490409)

---
 plugins/emoticons/composer.json       |    2 +-
 plugins/emoticons/tests/Emoticons.php |   42 +++++++++++++++++++++++++++++++++++++++++-
 plugins/emoticons/emoticons.php       |    8 ++++----
 3 files changed, 46 insertions(+), 6 deletions(-)

diff --git a/plugins/emoticons/composer.json b/plugins/emoticons/composer.json
index 8e7b90a..d1679cf 100644
--- a/plugins/emoticons/composer.json
+++ b/plugins/emoticons/composer.json
@@ -3,7 +3,7 @@
     "type": "roundcube-plugin",
     "description": "Sample plugin to replace emoticons in plain text message body with real icons.",
     "license": "GPLv3+",
-    "version": "1.3",
+    "version": "1.4",
     "authors": [
         {
             "name": "Thomas Bruederli",
diff --git a/plugins/emoticons/emoticons.php b/plugins/emoticons/emoticons.php
index 187e838..f3f987a 100644
--- a/plugins/emoticons/emoticons.php
+++ b/plugins/emoticons/emoticons.php
@@ -36,8 +36,6 @@
 
         // map of emoticon replacements
         $map = array(
-            '/:\)/'             => $this->img_tag('smiley-smile.gif',       ':)'    ),
-            '/:-\)/'            => $this->img_tag('smiley-smile.gif',       ':-)'   ),
             '/(?<!mailto):D/'   => $this->img_tag('smiley-laughing.gif',    ':D'    ),
             '/:-D/'             => $this->img_tag('smiley-laughing.gif',    ':-D'   ),
             '/:\(/'             => $this->img_tag('smiley-frown.gif',       ':('    ),
@@ -54,8 +52,10 @@
             '/(?<!mailto):-@/i' => $this->img_tag('smiley-yell.gif',        ':-@'   ),
             '/O:\)/i'           => $this->img_tag('smiley-innocent.gif',    'O:)'   ),
             '/O:-\)/i'          => $this->img_tag('smiley-innocent.gif',    'O:-)'  ),
-            '/(?<!mailto):$/'   => $this->img_tag('smiley-embarassed.gif',  ':$'    ),
-            '/(?<!mailto):-$/'  => $this->img_tag('smiley-embarassed.gif',  ':-$'   ),
+            '/(?<!O):\)/'       => $this->img_tag('smiley-smile.gif',       ':)'    ),
+            '/(?<!O):-\)/'      => $this->img_tag('smiley-smile.gif',       ':-)'   ),
+            '/(?<!mailto):\$/'  => $this->img_tag('smiley-embarassed.gif',  ':$'    ),
+            '/(?<!mailto):-\$/' => $this->img_tag('smiley-embarassed.gif',  ':-$'   ),
             '/(?<!mailto):\*/i'  => $this->img_tag('smiley-kiss.gif',       ':*'    ),
             '/(?<!mailto):-\*/i' => $this->img_tag('smiley-kiss.gif',       ':-*'   ),
             '/(?<!mailto):S/i'  => $this->img_tag('smiley-undecided.gif',   ':S'    ),
diff --git a/plugins/emoticons/tests/Emoticons.php b/plugins/emoticons/tests/Emoticons.php
index e045022..14c7fd0 100644
--- a/plugins/emoticons/tests/Emoticons.php
+++ b/plugins/emoticons/tests/Emoticons.php
@@ -19,5 +19,45 @@
         $this->assertInstanceOf('emoticons', $plugin);
         $this->assertInstanceOf('rcube_plugin', $plugin);
     }
-}
 
+    /**
+     * replace() method tests
+     */
+    function test_replace()
+    {
+        $rcube  = rcube::get_instance();
+        $plugin = new emoticons($rcube->api);
+
+        $map = array(
+            ':D'  => array('smiley-laughing.gif',    ':D'    ),
+            ':-D' => array('smiley-laughing.gif',    ':-D'   ),
+            ':('  => array('smiley-frown.gif',       ':('    ),
+            ':-(' => array('smiley-frown.gif',       ':-('   ),
+            '8)'  => array('smiley-cool.gif',        '8)'    ),
+            '8-)' => array('smiley-cool.gif',        '8-)'   ),
+            ':O'  => array('smiley-surprised.gif',   ':O'    ),
+            ':-O' => array('smiley-surprised.gif',   ':-O'   ),
+            ':P'  => array('smiley-tongue-out.gif',  ':P'    ),
+            ':-P' => array('smiley-tongue-out.gif',  ':-P'   ),
+            ':@'  => array('smiley-yell.gif',        ':@'    ),
+            ':-@' => array('smiley-yell.gif',        ':-@'   ),
+            'O:)' => array('smiley-innocent.gif',    'O:)'   ),
+            'O:-)' => array('smiley-innocent.gif',    'O:-)' ),
+            ':)'  => array('smiley-smile.gif',       ':)'    ),
+            ':-)' => array('smiley-smile.gif',       ':-)'   ),
+            ':$'  => array('smiley-embarassed.gif',  ':$'    ),
+            ':-$' => array('smiley-embarassed.gif',  ':-$'   ),
+            ':*'  => array('smiley-kiss.gif',       ':*'     ),
+            ':-*' => array('smiley-kiss.gif',       ':-*'    ),
+            ':S'  => array('smiley-undecided.gif',   ':S'    ),
+            ':-S' => array('smiley-undecided.gif',   ':-S'   ),
+        );
+
+        foreach ($map as $body => $expected) {
+            $args = array('type' => 'plain', 'body' => $body);
+            $args = $plugin->replace($args);
+            $this->assertRegExp('/' . preg_quote($expected[0], '/') . '/', $args['body']);
+            $this->assertRegExp('/title="' . preg_quote($expected[1], '/') . '"/', $args['body']);
+        }
+    }
+}

--
Gitblit v1.9.1