diff --git a/kallithea/lib/helpers.py b/kallithea/lib/helpers.py --- a/kallithea/lib/helpers.py +++ b/kallithea/lib/helpers.py @@ -57,7 +57,7 @@ from kallithea.lib.utils import repo_nam from kallithea.lib.utils2 import str2bool, safe_unicode, safe_str, \ get_changeset_safe, datetime_to_time, time_to_datetime, AttributeDict,\ safe_int -from kallithea.lib.markup_renderer import MarkupRenderer +from kallithea.lib.markup_renderer import MarkupRenderer, url_re from kallithea.lib.vcs.exceptions import ChangesetDoesNotExistError from kallithea.lib.vcs.backends.base import BaseChangeset, EmptyChangeset from kallithea.config.conf import DATE_FORMAT, DATETIME_FORMAT @@ -1256,13 +1256,10 @@ def urlify_text(text_, safe=True): :param text_: """ - url_pat = re.compile(r'''(http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+#]''' - '''|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+)''') - def url_func(match_obj): url_full = match_obj.groups()[0] return '%(url)s' % ({'url': url_full}) - _newtext = url_pat.sub(url_func, text_) + _newtext = url_re.sub(url_func, text_) if safe: return literal(_newtext) return _newtext diff --git a/kallithea/lib/markup_renderer.py b/kallithea/lib/markup_renderer.py --- a/kallithea/lib/markup_renderer.py +++ b/kallithea/lib/markup_renderer.py @@ -35,6 +35,9 @@ from kallithea.lib.utils2 import safe_un log = logging.getLogger(__name__) +url_re = re.compile(r'''(\bhttps?://(?:[\da-zA-Z0-9@:.-]+)''' + r'''(?:[/a-zA-Z0-9_=@#~&+%.,:?!*()-]*[/a-zA-Z0-9_=@#~])?)''') + class MarkupRenderer(object): RESTRUCTUREDTEXT_DISALLOWED_DIRECTIVES = ['include', 'meta', 'raw'] @@ -127,17 +130,11 @@ class MarkupRenderer(object): if universal_newline: newline = '\n' source = newline.join(source.splitlines()) - def urlify_text(text): - url_pat = re.compile(r'(http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+#]' - '|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+)') - def url_func(match_obj): - url_full = match_obj.groups()[0] - return '%(url)s' % ({'url': url_full}) - - return url_pat.sub(url_func, text) - - source = urlify_text(source) + def url_func(match_obj): + url_full = match_obj.groups()[0] + return '%(url)s' % ({'url': url_full}) + source = url_re.sub(url_func, source) return '
' + source.replace("\n", '
') @classmethod