From df2de9c1759e43588ab07a7ffc491e66707e8d30 Mon Sep 17 00:00:00 2001 From: Tom Gross Date: Fri, 29 May 2015 13:41:22 +0000 Subject: [PATCH] remove CMFDefault dependency --- .../PortalTransforms/transforms/html_body.py | 2 +- .../transforms/pdf_to_html.py | 2 +- .../transforms/rtf_to_html.py | 2 +- .../PortalTransforms/transforms/safe_html.py | 76 ++++++++++++++++--- 4 files changed, 68 insertions(+), 14 deletions(-) diff --git a/Products/PortalTransforms/transforms/html_body.py b/Products/PortalTransforms/transforms/html_body.py index e03fdaa..78181ab 100644 --- a/Products/PortalTransforms/transforms/html_body.py +++ b/Products/PortalTransforms/transforms/html_body.py @@ -1,6 +1,6 @@ from Products.PortalTransforms.interfaces import ITransform from zope.interface import implements -from Products.CMFDefault.utils import bodyfinder +from Products.PortalTransforms.libtransforms.utils import bodyfinder class HTMLBody: diff --git a/Products/PortalTransforms/transforms/pdf_to_html.py b/Products/PortalTransforms/transforms/pdf_to_html.py index 8c6159d..27f9f24 100644 --- a/Products/PortalTransforms/transforms/pdf_to_html.py +++ b/Products/PortalTransforms/transforms/pdf_to_html.py @@ -7,7 +7,7 @@ from Products.PortalTransforms.libtransforms.utils import sansext from Products.PortalTransforms.libtransforms.commandtransform import ( commandtransform, popentransform) -from Products.CMFDefault.utils import bodyfinder +from Products.PortalTransforms.libtransforms.utils import bodyfinder import os diff --git a/Products/PortalTransforms/transforms/rtf_to_html.py b/Products/PortalTransforms/transforms/rtf_to_html.py index cb50d20..7df9d68 100644 --- a/Products/PortalTransforms/transforms/rtf_to_html.py +++ b/Products/PortalTransforms/transforms/rtf_to_html.py @@ -5,9 +5,9 @@ from Products.PortalTransforms.interfaces import ITransform from zope.interface import implements from Products.PortalTransforms.libtransforms.utils import sansext +from Products.PortalTransforms.libtransforms.utils import bodyfinder from Products.PortalTransforms.libtransforms.commandtransform import \ commandtransform -from Products.CMFDefault.utils import bodyfinder import os diff --git a/Products/PortalTransforms/transforms/safe_html.py b/Products/PortalTransforms/transforms/safe_html.py index 255a878..e5e243c 100644 --- a/Products/PortalTransforms/transforms/safe_html.py +++ b/Products/PortalTransforms/transforms/safe_html.py @@ -6,17 +6,74 @@ from Products.PortalTransforms.interfaces import ITransform from zope.interface import implements from Products.PortalTransforms.utils import log -from Products.CMFDefault.utils import bodyfinder -from Products.CMFDefault.utils import IllegalHTML -from Products.CMFDefault.utils import VALID_TAGS -from Products.CMFDefault.utils import NASTY_TAGS +from Products.PortalTransforms.libtransforms.utils import bodyfinder from Products.PortalTransforms.utils import safeToInt -# tag mapping: tag -> short or long tag -VALID_TAGS = VALID_TAGS.copy() -NASTY_TAGS = NASTY_TAGS.copy() +class IllegalHTML(ValueError): + """ Illegal HTML error. + """ + + +# These are the HTML tags that we will leave intact +VALID_TAGS = { 'a' : 1 + , 'b' : 1 + , 'base' : 0 + , 'big' : 1 + , 'blockquote' : 1 + , 'body' : 1 + , 'br' : 0 + , 'caption' : 1 + , 'cite' : 1 + , 'code' : 1 + , 'dd' : 1 + , 'div' : 1 + , 'dl' : 1 + , 'dt' : 1 + , 'em' : 1 + , 'h1' : 1 + , 'h2' : 1 + , 'h3' : 1 + , 'h4' : 1 + , 'h5' : 1 + , 'h6' : 1 + , 'head' : 1 + , 'hr' : 0 + , 'html' : 1 + , 'i' : 1 + , 'img' : 0 + , 'kbd' : 1 + , 'li' : 1 + # , 'link' : 1 type="script" hoses us + , 'meta' : 0 + , 'ol' : 1 + , 'p' : 1 + , 'pre' : 1 + , 'small' : 1 + , 'span' : 1 + , 'strong' : 1 + , 'sub' : 1 + , 'sup' : 1 + , 'table' : 1 + , 'tbody' : 1 + , 'td' : 1 + , 'th' : 1 + , 'title' : 1 + , 'tr' : 1 + , 'tt' : 1 + , 'u' : 1 + , 'ul' : 1 + } + +NASTY_TAGS = { 'script' : 1 + , 'object' : 1 + , 'embed' : 1 + , 'applet' : 1 + , 'style' : 1 # this helps improve Word HTML cleanup. + , 'meta' : 1 # allowed by parsers, but can cause unexpected behavior + } + -# add some tags to allowed types. These should be backported to CMFDefault. +# add some tags to allowed types. VALID_TAGS['ins'] = 1 VALID_TAGS['del'] = 1 VALID_TAGS['q'] = 1 @@ -61,9 +118,6 @@ VALID_TAGS['time'] = 1 VALID_TAGS['video'] = 1 -# add some tags to nasty. -NASTY_TAGS['style'] = 1 # this helps improve Word HTML cleanup. -NASTY_TAGS['meta'] = 1 # allowed by parsers, but can cause unexpected behavior msg_pat = """