Opened 9 years ago

Last modified 4 years ago

#2123 new defect

Installing Emoticons Can Damage Existing Text (i.e. Dialing codes '(8)' )

Reported by: ryan.gossink@… Owned by: Olemis Lang
Priority: normal Component: EmoticonsPlugin
Severity: normal Keywords:
Cc: Trac Release: 0.10


The following change addreses his by requiring emoticons be encapsulated in square brackets before being parsed by the plugin:

# -*- coding: utf-8 -*-
# Copyright (C) 2005 Christopher Lenz <>
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

import re
from pkg_resources import resource_filename

from trac.core import *
from trac.util import escape
from import ITemplateProvider
from import IWikiSyntaxProvider

    ':/': 'annoyed.png', ':-/': 'annoyed.png',
    '8)': 'cool.png', '8-)': 'cool.png', 'B)': 'cool.png', 'B-)': 'cool.png',
    ':(': 'frown.png', ':-(': 'frown.png',
    ':D': 'happy.png', ':-D': 'happy.png',
    ':P': 'razz.png', ':-P': 'razz.png',
    ':)': 'smile.png', ':-)': 'smile.png',
    ':|': 'stoic.png', ':-|': 'stoic.png',
    ':O': 'suprised.png', ':o': 'suprised.png', ':-O': 'suprised.png',
    ':-o': 'suprised.png',
    ';)': 'wink.png', ';-)': 'wink.png'

class EmoticonsSupport(Component):
    """Provides support for graphical emoticons in wiki-formatted text."""

    implements(ITemplateProvider, IWikiSyntaxProvider)

    # ITemplateProvider methods

    def get_htdocs_dirs(self):
        """Return the directories containing static resources."""
        return [('emoticons', resource_filename(__name__, 'icons'))]

    def get_templates_dirs(self):
        return []

    # IWikiSyntaxProvider methods

    def get_wiki_syntax(self):
        """Replace textual patterns representing emoticons with the
        corresponding icon."""
        def _replace(formatter, namespace, match):
            src ='emoticons', EMOTICONS[[1:-1]])
            return '<img src="%s" alt="%s" class="emoticon" width="18" ' \
                   'height="18" style="vertical-align: middle" />' % (
                   escape(src), escape(
        pattern = '|'.join([re.escape('[' + pattern + ']') for pattern in EMOTICONS])
        yield '\b' + pattern + '\b', _replace

    def get_link_resolvers(self):
        return []

Attachments (0)

Change History (4)

comment:1 Changed 6 years ago by Ryan J Ollos

Reporter: changed from anonymousryan.gossink@… to ryan.gossink@…

comment:2 Changed 6 years ago by Ryan J Ollos

Owner: changed from Christopher Lenz to Ryan J Ollos
Status: newassigned

comment:3 Changed 5 years ago by Ryan J Ollos

Owner: changed from Ryan J Ollos to anonymous
Status: assignednew

comment:4 Changed 4 years ago by Ryan J Ollos

Owner: changed from anonymous to Olemis Lang

Modify Ticket

Change Properties
Set your email in Preferences
as new The owner will remain Olemis Lang.

Add Comment

E-mail address and name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.