allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [2/2] allura git commit: [#7896] strip out HTML already generated by markdown in multi-step commit email situation
Date Thu, 06 Jul 2017 19:51:33 GMT
[#7896] strip out HTML already generated by markdown in multi-step commit email situation


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/adf67f5d
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/adf67f5d
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/adf67f5d

Branch: refs/heads/db/8157
Commit: adf67f5d7fd0b6973d8c907583e39ef7d64fe88c
Parents: a113534
Author: Dave Brondsema <dave@brondsema.net>
Authored: Thu Jul 6 13:48:15 2017 -0400
Committer: Dave Brondsema <dave@brondsema.net>
Committed: Thu Jul 6 15:51:12 2017 -0400

----------------------------------------------------------------------
 Allura/allura/tasks/mail_tasks.py               |  13 +++++
 ForgeGit/forgegit/data/post-receive_tmpl        |   0
 .../21/9eee531d76e32cce4e04badc4e821fbfba0d33   | Bin 0 -> 218 bytes
 .../b8/5dfbec3a5d08677bdd402fc0338934f623a234   | Bin 0 -> 217 bytes
 .../f1/adef63cb08891a0942b76fc4b9c50c6c494bc7   | Bin 0 -> 29 bytes
 .../data/weird-chars.git/refs/heads/master      |   2 +-
 .../forgegit/tests/model/test_repository.py     |  49 +++++++++++++++++++
 rat-excludes.txt                                |   1 -
 8 files changed, 63 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/adf67f5d/Allura/allura/tasks/mail_tasks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tasks/mail_tasks.py b/Allura/allura/tasks/mail_tasks.py
index 16c2f1f..a5af0a6 100644
--- a/Allura/allura/tasks/mail_tasks.py
+++ b/Allura/allura/tasks/mail_tasks.py
@@ -17,9 +17,11 @@
 
 import logging
 import HTMLParser
+import re
 
 from pylons import tmpl_context as c, app_globals as g, config
 from bson import ObjectId
+import markupsafe
 
 from allura.lib import helpers as h
 from allura.lib.decorators import task
@@ -111,7 +113,18 @@ def create_multipart_msg(text, metalink=None):
     :return:
     """
 
+    def replace_html(matchobj):
+        text_within_div = matchobj.group(1)
+        text_within_div = text_within_div.replace('</p>', '\n')
+        text_within_div = markupsafe._striptags_re.sub('', text_within_div)
+        return text_within_div
+
     plain_text = text
+    plain_text = re.sub(r'<div class="markdown_content">(.*)</div>',  # strip
HTML from markdown generated blocks
+                        replace_html,
+                        plain_text,
+                        flags=re.DOTALL,  # match newlines too
+                        )
     plain_text = HTMLParser.HTMLParser().unescape(plain_text)  # put literal HTML tags back
into plaintext
     plain_msg = mail_util.encode_email_part(plain_text, 'plain')
 

http://git-wip-us.apache.org/repos/asf/allura/blob/adf67f5d/ForgeGit/forgegit/data/post-receive_tmpl
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/data/post-receive_tmpl b/ForgeGit/forgegit/data/post-receive_tmpl
deleted file mode 100644
index e69de29..0000000

http://git-wip-us.apache.org/repos/asf/allura/blob/adf67f5d/ForgeGit/forgegit/tests/data/weird-chars.git/objects/21/9eee531d76e32cce4e04badc4e821fbfba0d33
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/data/weird-chars.git/objects/21/9eee531d76e32cce4e04badc4e821fbfba0d33
b/ForgeGit/forgegit/tests/data/weird-chars.git/objects/21/9eee531d76e32cce4e04badc4e821fbfba0d33
new file mode 100644
index 0000000..e85399a
Binary files /dev/null and b/ForgeGit/forgegit/tests/data/weird-chars.git/objects/21/9eee531d76e32cce4e04badc4e821fbfba0d33
differ

http://git-wip-us.apache.org/repos/asf/allura/blob/adf67f5d/ForgeGit/forgegit/tests/data/weird-chars.git/objects/b8/5dfbec3a5d08677bdd402fc0338934f623a234
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/data/weird-chars.git/objects/b8/5dfbec3a5d08677bdd402fc0338934f623a234
b/ForgeGit/forgegit/tests/data/weird-chars.git/objects/b8/5dfbec3a5d08677bdd402fc0338934f623a234
new file mode 100644
index 0000000..e913060
Binary files /dev/null and b/ForgeGit/forgegit/tests/data/weird-chars.git/objects/b8/5dfbec3a5d08677bdd402fc0338934f623a234
differ

http://git-wip-us.apache.org/repos/asf/allura/blob/adf67f5d/ForgeGit/forgegit/tests/data/weird-chars.git/objects/f1/adef63cb08891a0942b76fc4b9c50c6c494bc7
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/data/weird-chars.git/objects/f1/adef63cb08891a0942b76fc4b9c50c6c494bc7
b/ForgeGit/forgegit/tests/data/weird-chars.git/objects/f1/adef63cb08891a0942b76fc4b9c50c6c494bc7
new file mode 100644
index 0000000..c08ecd5
Binary files /dev/null and b/ForgeGit/forgegit/tests/data/weird-chars.git/objects/f1/adef63cb08891a0942b76fc4b9c50c6c494bc7
differ

http://git-wip-us.apache.org/repos/asf/allura/blob/adf67f5d/ForgeGit/forgegit/tests/data/weird-chars.git/refs/heads/master
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/data/weird-chars.git/refs/heads/master b/ForgeGit/forgegit/tests/data/weird-chars.git/refs/heads/master
index 20663de..81ca180 100644
--- a/ForgeGit/forgegit/tests/data/weird-chars.git/refs/heads/master
+++ b/ForgeGit/forgegit/tests/data/weird-chars.git/refs/heads/master
@@ -1 +1 @@
-616d24f8dd4e95cadd8e93df5061f09855d1a066
+b85dfbec3a5d08677bdd402fc0338934f623a234

http://git-wip-us.apache.org/repos/asf/allura/blob/adf67f5d/ForgeGit/forgegit/tests/model/test_repository.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/model/test_repository.py b/ForgeGit/forgegit/tests/model/test_repository.py
index 8dbf931..222a11f 100644
--- a/ForgeGit/forgegit/tests/model/test_repository.py
+++ b/ForgeGit/forgegit/tests/model/test_repository.py
@@ -434,6 +434,54 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
         assert n.text.startswith('\n## Branch: master'), n.text
         assert n.text.endswith('And 1 more commits.\n'), n.text
 
+    @td.with_tool('test', 'Git', 'weird-chars', 'WeirdChars', type='git')
+    def _setup_weird_chars_repo(self):
+        h.set_context('test', 'weird-chars', neighborhood='Projects')
+        repo_dir = pkg_resources.resource_filename('forgegit', 'tests/data')
+        c.app.repo.fs_path = repo_dir
+        c.app.repo.status = 'ready'
+        c.app.repo.name = 'weird-chars.git'
+        ThreadLocalORMSession.flush_all()
+        c.app.repo.refresh()
+
+    def test_notification_html_and_plaintext(self):
+        M.MonQTask.query.remove({})  # remove other stuff from setup()
+        self._setup_weird_chars_repo()
+
+        with mock.patch('allura.tasks.mail_tasks.smtp_client.sendmail') as sendmail:
+            while M.MonQTask.run_ready():  # have to run them all multiple times since one
task creates another
+                pass
+        text_msg = sendmail.call_args_list[1][0][6]
+        html_msg = sendmail.call_args_list[2][0][6]
+        text_body = text_msg.get_payload(decode=True)
+        html_body = html_msg.get_payload(decode=True)
+
+        # no extra HTML in commit messages
+        assert_in('''-----
+
+Add foo.txt.  Commit ref [616d24f8dd4e95cadd8e93df5061f09855d1a066] *bold* <b>bold</b>
+
+* one
+* two
+* three
+
+http://example.com/
+
+By Dave Brondsema''', text_body)
+        # these bracketed links could look like HTML tags, ensure they don't get removed
+        assert_in('further messages, please visit <http://localhost:8080/auth/subscriptions/>',
text_body)
+
+        # limited markdown handling of commit messages (see `markdown_commit`)
+        # and HTML escaped
+        assert_in('''<hr/>
+<div class="markdown_content"><p>Add foo.txt.  Commit ref <a class="alink"
href="http://localhost:8080/p/test/weird-chars/ci/616d24f8dd4e95cadd8e93df5061f09855d1a066/">[616d24f8dd4e95cadd8e93df5061f09855d1a066]</a>
*bold* &lt;b&gt;bold&lt;/b&gt;</p>
+<p>* one<br/>
+* two<br/>
+* three</p>
+<p>http://example.com/</p></div>
+
+<p>By Dave Brondsema''', html_body)
+
     def test_tarball(self):
         tmpdir = tg.config['scm.repos.tarball.root']
         if os.path.isfile(os.path.join(tmpdir, "git/t/te/test/testgit.git/test-src-git-HEAD.zip")):
@@ -895,6 +943,7 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
             tags = rev._impl._get_refs('tags')
             assert_equal(rev.cached_tags, tags)
 
+
 class TestGitImplementation(unittest.TestCase):
 
     def test_branches(self):

http://git-wip-us.apache.org/repos/asf/allura/blob/adf67f5d/rat-excludes.txt
----------------------------------------------------------------------
diff --git a/rat-excludes.txt b/rat-excludes.txt
index d36e26e..6397d06 100644
--- a/rat-excludes.txt
+++ b/rat-excludes.txt
@@ -59,7 +59,6 @@ Allura/docs/Makefile
 Allura/docs/_build/
 Allura/run/dummy.txt
 CHANGES
-ForgeGit/forgegit/data/post-receive_tmpl
 ForgeImporters/docs/make.bat
 ForgeImporters/docs/Makefile
 ForgeImporters/forgeimporters/trac/tests/data/test-list.csv


Mime
View raw message