[cpif] r206 - trunk/frontend-web
svn at argo.es
svn at argo.es
Sat Jun 30 19:38:27 CEST 2007
Author: alvaro
Date: Sat Jun 30 19:38:26 2007
New Revision: 206
Log:
Arreglos en la gestion de las entidades
Modified:
trunk/frontend-web/parser_bbcode.py
trunk/frontend-web/parser_html.py
trunk/frontend-web/parsers.py
Modified: trunk/frontend-web/parser_bbcode.py
==============================================================================
--- trunk/frontend-web/parser_bbcode.py (original)
+++ trunk/frontend-web/parser_bbcode.py Sat Jun 30 19:38:26 2007
@@ -29,7 +29,7 @@
"img": ('<img src="%(arg)s" />', None, True)
}
-from parser_html import escape
+from parser_html import escape, unescape
class BBCodeParser:
@@ -72,7 +72,8 @@
aux = allowed_tags[tag[0]]
if not tag[1]:
aux = allowed_tags.get(tag[0] + "*", aux) # Permitimos tag* que no lleva argumentos y puede ser distinto
- return aux[0] % {"arg": escape(tag[1].strip('"')) if tag[1] else '' }
+ tag[1] = unescape(tag[1].strip('"')) if tag[1] else ""
+ return aux[0] % {"arg": escape(tag[1]) if tag[1] else '' }
def _tag_closes(self, tag):
"""Returns true if the tags needs to be closed"""
@@ -180,6 +181,8 @@
('antes [url="la direccion"]el texto[/url] despues', 'antes <a href="la direccion">el texto</a> despues'),
('[url="la direccion"]el texto[/url]', '<a href="la direccion">el texto</a>'),
+
+ ('[url="http://example.org/uno&dos"]el texto[/url]', '<a href="http://example.org/uno&dos">el texto</a>'),
('[url=la direccion]el texto[/url]', '<a href="la direccion">el texto</a>'),
('antes [url=la direccion]el texto[/url]', 'antes <a href="la direccion">el texto</a>'),
Modified: trunk/frontend-web/parser_html.py
==============================================================================
--- trunk/frontend-web/parser_html.py (original)
+++ trunk/frontend-web/parser_html.py Sat Jun 30 19:38:26 2007
@@ -26,6 +26,17 @@
import xml.sax.saxutils
return xml.sax.saxutils.escape(text, entities)
+def unescape(text):
+ entities = {
+# '<':'<',
+# '>':'>',
+ '"': '"',
+ "'": "'"
+# "&": "&"
+ }
+ import xml.sax.saxutils
+ return xml.sax.saxutils.unescape(text, entities)
+
from sgmllib import SGMLParser, SGMLParseError
class HTMLParser(SGMLParser):
def __init__(self, allow=True):
Modified: trunk/frontend-web/parsers.py
==============================================================================
--- trunk/frontend-web/parsers.py (original)
+++ trunk/frontend-web/parsers.py Sat Jun 30 19:38:26 2007
@@ -18,7 +18,29 @@
return parser_eol.parse(text)
+import unittest
+class TestBBCodeHTML(unittest.TestCase):
+ """Test Case for the BBCode and HTML parser together"""
+ correct_bbcode = (
+ ('[url="http://example.org/uno&dos"]el texto[/url]', '<a href="http://example.org/uno&dos">el texto</a>'),
+ ('[url="http://example.org/uno&dos"]el & texto[/url]', '<a href="http://example.org/uno&dos">el & texto</a>'),
+ ('[url="http://example.org/uno&dos"]el & texto[/url]', '<a href="http://example.org/uno&dos">el &amp; texto</a>'),
+ ('[url="http://example.org/uno&dos"]el "" texto[/url]', '<a href="http://example.org/uno&dos">el "" texto</a>'),
+)
+
+ def testCorrectBBCode(self):
+ """Test if the translation goes well."""
+ global allow_errors
+ allow_errors = False
+ for bbcode, html in self.correct_bbcode:
+ retval, result = convert_to_html(bbcode)
+ assert not retval
+ self.assertEqual(html, result)
+ retval, result = convert_to_html(bbcode)
+ assert not retval
+ self.assertEqual(html, result)
+
if __name__ == "__main__":
test1 = parser_html.TestHTML
test2 = parser_bbcode.TestBBCode
More information about the cpif
mailing list