# HG changeset patch # User Mads Kiilerich # Date 1604936563 -3600 # Node ID 0383ed91d4ed6d5d4fbfcb6f3ce56df0f82381d3 # Parent f375751fe3fabc0a8607f86ec4d5d8447c11a8c0 lib: move url_re to webutils diff -r f375751fe3fa -r 0383ed91d4ed kallithea/lib/helpers.py --- a/kallithea/lib/helpers.py Mon Nov 09 16:42:43 2020 +0100 +++ b/kallithea/lib/helpers.py Mon Nov 09 16:42:43 2020 +0100 @@ -36,7 +36,6 @@ #============================================================================== from kallithea.lib.auth import HasPermissionAny, HasRepoGroupPermissionLevel, HasRepoPermissionLevel from kallithea.lib.diffs import BIN_FILENODE, CHMOD_FILENODE, DEL_FILENODE, MOD_FILENODE, NEW_FILENODE, RENAMED_FILENODE -from kallithea.lib.markup_renderer import url_re from kallithea.lib.pygmentsutils import get_custom_lexer from kallithea.lib.utils2 import (AttributeDict, age, asbool, credentials_filter, fmt_date, link_to_ref, safe_bytes, safe_int, safe_str, shorter, time_to_datetime) @@ -48,7 +47,7 @@ from kallithea.lib.vcs.utils import author_email, author_name from kallithea.lib.webutils import (HTML, MENTIONS_REGEX, Option, canonical_url, checkbox, chop_at, end_form, escape, form, format_byte_size, hidden, html_escape, js, jshtml, link_to, literal, password, pop_flash_messages, radio, reset, safeid, select, - session_csrf_secret_name, session_csrf_secret_token, submit, text, textarea, truncate, url, wrap_paragraphs) + session_csrf_secret_name, session_csrf_secret_token, submit, text, textarea, truncate, url, url_re, wrap_paragraphs) from kallithea.model import db from kallithea.model.changeset_status import ChangesetStatusModel diff -r f375751fe3fa -r 0383ed91d4ed kallithea/lib/markup_renderer.py --- a/kallithea/lib/markup_renderer.py Mon Nov 09 16:42:43 2020 +0100 +++ b/kallithea/lib/markup_renderer.py Mon Nov 09 16:42:43 2020 +0100 @@ -42,10 +42,6 @@ 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'] @@ -163,7 +159,7 @@ def url_func(match_obj): url_full = match_obj.group(0) return '%(url)s' % ({'url': url_full}) - source = url_re.sub(url_func, source) + source = webutils.url_re.sub(url_func, source) return '
' + source.replace("\n", '
') @classmethod diff -r f375751fe3fa -r 0383ed91d4ed kallithea/lib/webutils.py --- a/kallithea/lib/webutils.py Mon Nov 09 16:42:43 2020 +0100 +++ b/kallithea/lib/webutils.py Mon Nov 09 16:42:43 2020 +0100 @@ -309,6 +309,10 @@ return js(escape(val)) +url_re = re.compile(r'''\bhttps?://(?:[\da-zA-Z0-9@:.-]+)''' + r'''(?:[/a-zA-Z0-9_=@#~&+%.,:;?!*()-]*[/a-zA-Z0-9_=@#~])?''') + + # Must match regexp in kallithea/public/js/base.js MentionsAutoComplete() # Check char before @ - it must not look like we are in an email addresses. # Matching is greedy so we don't have to look beyond the end.