From 7ed3e7e04746e55f0fbb300b9bf7ab256fb39663 Mon Sep 17 00:00:00 2001 From: Marcin Kuzminski Date: Mon, 13 Mar 2017 11:17:00 +0100 Subject: [PATCH] makrup-renderer: fix some cases which could cause lxml errors, skip js flags --- rhodecode/lib/markup_renderer.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/rhodecode/lib/markup_renderer.py b/rhodecode/lib/markup_renderer.py index 5375055a..df7e0ead 100644 --- 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_repo_file=None): 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