You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by tv...@apache.org on 2013/02/18 20:17:34 UTC
[1/2] git commit: [#5358] allow markdown escapes within autolinked
URLs
[#5358] allow markdown escapes within autolinked URLs
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/bdd590a1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/bdd590a1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/bdd590a1
Branch: refs/heads/master
Commit: bdd590a14134471c7e487f3cff1b9d1727d48148
Parents: b3429b2
Author: Dave Brondsema <db...@geek.net>
Authored: Tue Feb 5 20:38:47 2013 +0000
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Mon Feb 18 19:16:38 2013 +0000
----------------------------------------------------------------------
Allura/allura/lib/markdown_extensions.py | 6 +++++-
Allura/allura/tests/test_globals.py | 12 ++++++++----
2 files changed, 13 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/bdd590a1/Allura/allura/lib/markdown_extensions.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/markdown_extensions.py b/Allura/allura/lib/markdown_extensions.py
index c004db0..1f50876 100644
--- a/Allura/allura/lib/markdown_extensions.py
+++ b/Allura/allura/lib/markdown_extensions.py
@@ -38,7 +38,8 @@ class ForgeExtension(markdown.Extension):
md.preprocessors['fenced-code'] = FencedCodeProcessor()
md.preprocessors.add('plain_text_block', PlainTextPreprocessor(md), "_begin")
md.preprocessors.add('macro_include', ForgeMacroIncludePreprocessor(md), '_end')
- md.inlinePatterns['autolink_1'] = AutolinkPattern(r'(http(?:s?)://[a-zA-Z0-9./\-_0%?&=+#;~:]+)')
+ # this has to be before the 'escape' processor, otherwise weird placeholders are inserted for escaped chars within urls, and then the autolink can't match the whole url
+ md.inlinePatterns.add('autolink_without_brackets', AutolinkPattern(r'(http(?:s?)://[a-zA-Z0-9./\-\\_%?&=+#;~:]+)'), '<escape')
# replace the link pattern with our extended version
md.inlinePatterns['link'] = ForgeLinkPattern(markdown.inlinepatterns.LINK_RE, md, ext=self)
md.inlinePatterns['short_reference'] = ForgeLinkPattern(markdown.inlinepatterns.SHORT_REF_RE, md, ext=self)
@@ -280,6 +281,9 @@ class AutolinkPattern(markdown.inlinepatterns.LinkPattern):
old_link = mo.group(2)
result = markdown.util.etree.Element('a')
result.text = old_link
+ # since this is run before the builtin 'escape' processor, we have to do our own unescaping
+ for char in markdown.Markdown.ESCAPED_CHARS:
+ old_link = old_link.replace('\\' + char, char)
result.set('href', old_link)
return result
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/bdd590a1/Allura/allura/tests/test_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_globals.py b/Allura/allura/tests/test_globals.py
index cb53a0e..a11919c 100644
--- a/Allura/allura/tests/test_globals.py
+++ b/Allura/allura/tests/test_globals.py
@@ -259,14 +259,18 @@ def foo(): pass
def test_markdown_autolink():
- #with h.set_context('test', 'wiki', neighborhood='Projects')
- text = g.markdown.convert('This is http://sf.net')
- assert '<a href=' in text, text
+ assert '<a href=' in g.markdown.convert('This is http://sf.net')
tgt = 'http://everything2.com/?node=nate+oostendorp'
s = g.markdown.convert('This is %s' % tgt)
assert_equal(
s, '<div class="markdown_content"><p>This is <a href="%s" rel="nofollow">%s</a></p></div>' % (tgt, tgt))
- assert '<a href=' in g.markdown.convert('This is http://sf.net')
+
+
+def test_markdown_autolink_with_escape():
+ # \_ is unnecessary but valid markdown escaping and should be considered as a regular underscore
+ # (it occurs during html2text conversion during project migrations)
+ r = g.markdown.convert('a http://www.phpmyadmin.net/home\_page/security/\#target b')
+ assert 'href="http://www.phpmyadmin.net/home_page/security/#target"' in r, r
def test_macro_projects():