diff --git a/kallithea/lib/helpers.py b/kallithea/lib/helpers.py
--- a/kallithea/lib/helpers.py
+++ b/kallithea/lib/helpers.py
@@ -1156,17 +1156,15 @@ def urlify_issues(newtext, repo_name):
def issues_replace(match_obj,
issue_server_link=issue_server_link, issue_prefix=issue_prefix):
- leadingspace = ' ' if match_obj.group().startswith(' ') else ''
issue_id = ''.join(match_obj.groups())
issue_url = issue_server_link.replace('{id}', issue_id)
issue_url = issue_url.replace('{repo}', repo_name)
issue_url = issue_url.replace('{repo_name}', repo_name.split(URL_SEP)[-1])
return (
- '%(leadingspace)s'
+ ''
'%(issue-prefix)s%(id-repr)s'
''
) % {
- 'leadingspace': leadingspace,
'url': issue_url,
'id-repr': issue_id,
'issue-prefix': issue_prefix,
diff --git a/kallithea/lib/paster_commands/template.ini.mako b/kallithea/lib/paster_commands/template.ini.mako
--- a/kallithea/lib/paster_commands/template.ini.mako
+++ b/kallithea/lib/paster_commands/template.ini.mako
@@ -267,6 +267,9 @@ default_encoding = utf8
<%text>## pattern to get the issues from commit messages%text>
<%text>## default one used here is # with a regex passive group for `#`%text>
<%text>## {id} will be all groups matched from this pattern%text>
+<%text>## To require mandatory whitespace before the issue pattern, use:%text>
+<%text>## (?:^|(?<=\s)) before the actual pattern, and for mandatory whitespace%text>
+<%text>## behind the issue pattern, use (?:$|(?=\s)) after the actual pattern%text>
issue_pat = #(\d+)
diff --git a/kallithea/tests/other/test_libs.py b/kallithea/tests/other/test_libs.py
--- a/kallithea/tests/other/test_libs.py
+++ b/kallithea/tests/other/test_libs.py
@@ -411,22 +411,34 @@ class TestLibs(TestController):
'issue #123 and issue#456',
"""issue #123 and """
"""issue#456"""),
+ # following test case shows the result of a backward incompatible change that was made: the
+ # space between 'issue' and '#123' is removed, because the space is part of the pattern.
(r'(?:\s*#)(\d+)', 'http://foo/{repo}/issue/{id}', '#',
'issue #123 and issue#456',
- """issue #123 and """
+ """issue#123 and """
"""issue#456"""),
+ # to require whitespace before the issue reference, one may be tempted to use \b...
(r'\bPR(\d+)', 'http://foo/{repo}/issue/{id}', '#',
'issue PR123 and issuePR456',
"""issue #123 and """
"""issuePR456"""),
- # following test case shows that \b does not work well in combination with '#': the expectations
+ # ... but it turns out that \b does not work well in combination with '#': the expectations
# are reversed from what is actually happening.
(r'\b#(\d+)', 'http://foo/{repo}/issue/{id}', '#',
'issue #123 and issue#456',
"""issue #123 and """
"""issue#456"""),
- (r'[ \t]#(\d+)', 'http://foo/{repo}/issue/{id}', '#',
- 'issue #123 and issue#456',
+ # ... so maybe try to be explicit? Unfortunately the whitespace before the issue
+ # reference is not retained, again, because it is part of the pattern.
+ (r'(?:^|\s)#(\d+)', 'http://foo/{repo}/issue/{id}', '#',
+ '#15 and issue #123 and issue#456',
+ """#15 and """
+ """issue#123 and """
+ """issue#456"""),
+ # ... instead, use lookbehind assertions.
+ (r'(?:^|(?<=\s))#(\d+)', 'http://foo/{repo}/issue/{id}', '#',
+ '#15 and issue #123 and issue#456',
+ """#15 and """
"""issue #123 and """
"""issue#456"""),
(r'(?:pullrequest|pull request|PR|pr) ?#?(\d+)', 'http://foo/{repo}/issue/{id}', 'PR#',