# HG changeset patch # User Marcin Kuzminski # Date 2017-03-13 10:17:00 # Node ID 3683d34327c85f0e03714a6b5ea84547ba9e0946 # Parent 6bced565ab07182770b2971901c8205523e79375 makrup-renderer: fix some cases which could cause lxml errors, skip js flags diff --git a/rhodecode/lib/markup_renderer.py b/rhodecode/lib/markup_renderer.py --- a/rhodecode/lib/markup_renderer.py +++ b/rhodecode/lib/markup_renderer.py @@ -28,7 +28,6 @@ import os import lxml import logging import urlparse -import urllib from mako.lookup import TemplateLookup from mako.template import Template as MakoTemplate @@ -48,7 +47,14 @@ DEFAULT_COMMENTS_RENDERER = 'rst' def relative_links(html_source, server_path): - doc = lxml.html.fromstring(html_source) + if not html_source: + return html_source + + try: + doc = lxml.html.fromstring(html_source) + except Exception: + return html_source + for el in doc.cssselect('img, video'): src = el.attrib['src'] if src: @@ -86,7 +92,7 @@ def relative_path(path, request_path, is path = safe_unicode(path) request_path = safe_unicode(request_path) - if path.startswith((u'data:', u'#', u':')): + if path.startswith((u'data:', u'javascript:', u'#', u':')): # skip data, anchor, invalid links return path