Mercurial > kallithea
changeset 7171:f91844b26269
lib: fix detection of ' as issue reference
Commit 494c793cc160 changed HTML escaping to please HTML 4 email readers.
The HTML entity ''' was replaced by '''.
Unfortunately, the pound character '#' is often used to mark issue
references, like 'bug #56'. While this depends on the issue patterns
actually configured, this pattern is so common that we cannot expect users
to set their issue_pat regular expressions such that '{' is not
matched.
Instead, keep the original ''' replacement at first in method html_escape,
but introduce a final step that just replaces ''' with '''.
The order of replacement in urlify_text then changes from:
html_escape (to HTML4)
urlify_issues
to
html_escape (to HTML5)
urlify_issues
make HTML5 more like HTML4
Test coverage show the problem case being solved.
author | Thomas De Schampheleire <thomas.de_schampheleire@nokia.com> |
---|---|
date | Wed, 14 Feb 2018 09:12:17 +0100 |
parents | 28317fc212f4 |
children | 4d1837a9b504 |
files | kallithea/lib/helpers.py kallithea/tests/other/test_libs.py |
diffstat | 2 files changed, 8 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/lib/helpers.py Wed Feb 14 08:32:19 2018 +0100 +++ b/kallithea/lib/helpers.py Wed Feb 14 09:12:17 2018 +0100 @@ -85,7 +85,7 @@ .replace(">", ">") .replace("<", "<") .replace('"', """) - .replace("'", "'") # some mail readers use HTML 4 and doesn't support ' + .replace("'", "'") # Note: this is HTML5 not HTML4 and might not work in mails ) def js(value): @@ -1092,6 +1092,10 @@ # make href around everything that isn't a href already s = linkify_others(s, link_) s = s.replace('\r\n', '<br/>').replace('\n', '<br/>') + # Turn HTML5 into more valid HTML4 as required by some mail readers. + # (This is not done in one step in html_escape, because character codes like + # { risk to be seen as an issue reference due to the presence of '#'.) + s = s.replace("'", "'") return literal(s)
--- a/kallithea/tests/other/test_libs.py Wed Feb 14 08:32:19 2018 +0100 +++ b/kallithea/tests/other/test_libs.py Wed Feb 14 09:12:17 2018 +0100 @@ -381,8 +381,7 @@ """and not be followed by * or alphanumerical <b>*characters*</b>.""", "-"), ("HTML escaping: <abc> 'single' \"double\" &pointer", - # problem: ' is encoded as ' which however is interpreted as #39 and expanded to a issue link - """HTML escaping: <abc> &<a class="issue-tracker-link" href="https://issues.example.com/repo_name/issue/39">#39</a>;single&<a class="issue-tracker-link" href="https://issues.example.com/repo_name/issue/39">#39</a>; "double" &pointer""", + "HTML escaping: <abc> 'single' "double" &pointer", "-"), # tags are covered by test_tag_extractor ]) @@ -420,11 +419,10 @@ 'silly me, the URL does not contain {id}, BUG12345.', 'silly me, the URL does not contain {id}, <a class="issue-tracker-link" href="https://bar/repo_name/">BUG12345</a>.'), (r'(PR-\d+)', 'http://foo/{repo}/issue/{id}', '', 'interesting issue #123, err PR-56', 'interesting issue #123, err <a class="issue-tracker-link" href="http://foo/repo_name/issue/PR-56">PR-56</a>'), - # problem: ' is encoded as ' which however is interpreted as #39 and expanded to a issue link (r'#(\d+)', 'http://foo/{repo}/issue/{id}', '#', - "some 'standard' text with apostrophes", 'some &<a class="issue-tracker-link" href="http://foo/repo_name/issue/39">#39</a>;standard&<a class="issue-tracker-link" href="http://foo/repo_name/issue/39">#39</a>; text with apostrophes'), + "some 'standard' text with apostrophes", 'some 'standard' text with apostrophes'), (r'#(\d+)', 'http://foo/{repo}/issue/{id}', '#', - "some 'standard' issue #123", 'some &<a class="issue-tracker-link" href="http://foo/repo_name/issue/39">#39</a>;standard&<a class="issue-tracker-link" href="http://foo/repo_name/issue/39">#39</a>; issue <a class="issue-tracker-link" href="http://foo/repo_name/issue/123">#123</a>'), + "some 'standard' issue #123", 'some 'standard' issue <a class="issue-tracker-link" href="http://foo/repo_name/issue/123">#123</a>'), ]) def test_urlify_issues(self, issue_pat, issue_server, issue_prefix, sample, expected): from kallithea.lib.helpers import urlify_text