From 5e97e58df30598f570ad1d84d567c47891b53f51 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Tue, 2 Jul 2019 15:21:17 -0700 Subject: [PATCH] webhooks/freshdesk/doc.md: Remove unescape_rendered_html kludge. This reverts commit f476ec7fac7a68920fdf5e5f98f8034ff5a57c4c (#10312) and replaces it with a proper fix using Jinja2 raw blocks. Signed-off-by: Anders Kaseorg --- templates/tests/test_unicode_decimals.html | 5 --- .../tests/markdown/test_unicode_decimals.md | 1 - zerver/templatetags/app_filters.py | 10 ----- zerver/tests/test_templates.py | 16 ------- zerver/views/documentation.py | 8 ---- zerver/webhooks/freshdesk/doc.md | 44 ++++++++++--------- 6 files changed, 24 insertions(+), 60 deletions(-) delete mode 100644 templates/tests/test_unicode_decimals.html delete mode 100644 templates/zerver/tests/markdown/test_unicode_decimals.md diff --git a/templates/tests/test_unicode_decimals.html b/templates/tests/test_unicode_decimals.html deleted file mode 100644 index caa7a27f1f..0000000000 --- a/templates/tests/test_unicode_decimals.html +++ /dev/null @@ -1,5 +0,0 @@ -header - -{{ render_markdown_path("zerver/tests/markdown/test_unicode_decimals.md", {"unescape_rendered_html": unescape_rendered_html}) }} - -footer diff --git a/templates/zerver/tests/markdown/test_unicode_decimals.md b/templates/zerver/tests/markdown/test_unicode_decimals.md deleted file mode 100644 index c60c140460..0000000000 --- a/templates/zerver/tests/markdown/test_unicode_decimals.md +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/zerver/templatetags/app_filters.py b/zerver/templatetags/app_filters.py index 1ce517fc23..ec89900bc6 100644 --- a/zerver/templatetags/app_filters.py +++ b/zerver/templatetags/app_filters.py @@ -1,4 +1,3 @@ -from html import unescape from typing import Any, Dict, List, Optional import markdown @@ -148,13 +147,4 @@ def render_markdown_path(markdown_file_path: str, html = md_engine.convert(markdown_string) rendered_html = jinja.from_string(html).render(context) - if context.get('unescape_rendered_html', False): - # In some exceptional cases (such as our Freshdesk webhook docs), - # code blocks in some of our Markdown templates have characters such - # as '{' encoded as '{' to prevent clashes with Jinja2 syntax, - # but the encoded form never gets decoded because the text ends up - # inside a
 tag. So here, we explicitly "unescape" such characters
-        # if 'unescape_rendered_html' is True.
-        rendered_html = unescape(rendered_html)
-
     return mark_safe(rendered_html)
diff --git a/zerver/tests/test_templates.py b/zerver/tests/test_templates.py
index b6ab054a17..7426170c81 100644
--- a/zerver/tests/test_templates.py
+++ b/zerver/tests/test_templates.py
@@ -295,22 +295,6 @@ footer
         self.assertEqual(content_sans_whitespace,
                          expected_html_sans_whitespace)
 
-    def test_encoded_unicode_decimals_in_markdown_template(self) -> None:
-        template = get_template("tests/test_unicode_decimals.html")
-        context = {'unescape_rendered_html': False}
-        content = template.render(context)
-
-        content_sans_whitespace = content.replace(" ", "").replace('\n', '')
-        self.assertEqual(content_sans_whitespace,
-                         'header

{}

footer') - - context = {'unescape_rendered_html': True} - content = template.render(context) - - content_sans_whitespace = content.replace(" ", "").replace('\n', '') - self.assertEqual(content_sans_whitespace, - 'header

{}

footer') - def test_markdown_nested_code_blocks(self) -> None: template = get_template("tests/test_markdown.html") context = { diff --git a/zerver/views/documentation.py b/zerver/views/documentation.py index 4b9308410c..8444e34000 100644 --- a/zerver/views/documentation.py +++ b/zerver/views/documentation.py @@ -194,14 +194,6 @@ def integration_doc(request: HttpRequest, integration_name: str=REQ(default=None context['hubot_docs_url'] = integration.hubot_docs_url if isinstance(integration, EmailIntegration): context['email_gateway_example'] = settings.EMAIL_GATEWAY_EXAMPLE - if integration.name == 'freshdesk': - # In our Freshdesk docs, some nested code blocks have characters such - # as '{' encoded as '{' to prevent clashes with Jinja2 syntax, - # but the encoded form never gets rendered because the text ends up - # inside a
 tag. So here, we explicitly set a directive that
-        # a particular template should be "unescaped" before being displayed.
-        # Note that this value is used by render_markdown_path.
-        context['unescape_rendered_html'] = True
 
     doc_html_str = render_markdown_path(integration.doc, context)
 
diff --git a/zerver/webhooks/freshdesk/doc.md b/zerver/webhooks/freshdesk/doc.md
index e9d0099f45..c484b36499 100644
--- a/zerver/webhooks/freshdesk/doc.md
+++ b/zerver/webhooks/freshdesk/doc.md
@@ -28,20 +28,22 @@ integration!
    the following JSON into the **Content** box:
 
     ```
+    {% raw %}
     {"freshdesk_webhook":
         {
-            "triggered_event":"{{triggered_event}}",
-            "ticket_id":"{{ticket.id}}",
-            "ticket_url":"{{ticket.url}}",
-            "ticket_type":"{{ticket.ticket_type}}",
-            "ticket_subject":"{{ticket.subject}}",
-            "ticket_description":"{{ticket.description}}",
-            "ticket_status":"{{ticket.status}}",
-            "ticket_priority":"{{ticket.priority}}",
-            "requester_name":"{{ticket.requester.name}}",
-            "requester_email":"{{ticket.requester.email}}",
+            "triggered_event":"{{triggered_event}}",
+            "ticket_id":"{{ticket.id}}",
+            "ticket_url":"{{ticket.url}}",
+            "ticket_type":"{{ticket.ticket_type}}",
+            "ticket_subject":"{{ticket.subject}}",
+            "ticket_description":"{{ticket.description}}",
+            "ticket_status":"{{ticket.status}}",
+            "ticket_priority":"{{ticket.priority}}",
+            "requester_name":"{{ticket.requester.name}}",
+            "requester_email":"{{ticket.requester.email}}",
         }
     }
+    {% endraw %}
     ```
 
     Click **Save**.
@@ -74,20 +76,22 @@ integration!
    the following JSON into the **Content** box:
 
     ```
+    {% raw %}
     {"freshdesk_webhook":
         {
-            "triggered_event":"{{triggered_event}}",
-            "ticket_id":"{{ticket.id}}",
-            "ticket_url":"{{ticket.url}}",
-            "ticket_type":"{{ticket.ticket_type}}",
-            "ticket_subject":"{{ticket.subject}}",
-            "ticket_description":"{{ticket.description}}",
-            "ticket_status":"{{ticket.status}}",
-            "ticket_priority":"{{ticket.priority}}",
-            "requester_name":"{{ticket.requester.name}}",
-            "requester_email":"{{ticket.requester.email}}",
+            "triggered_event":"{{triggered_event}}",
+            "ticket_id":"{{ticket.id}}",
+            "ticket_url":"{{ticket.url}}",
+            "ticket_type":"{{ticket.ticket_type}}",
+            "ticket_subject":"{{ticket.subject}}",
+            "ticket_description":"{{ticket.description}}",
+            "ticket_status":"{{ticket.status}}",
+            "ticket_priority":"{{ticket.priority}}",
+            "requester_name":"{{ticket.requester.name}}",
+            "requester_email":"{{ticket.requester.email}}",
         }
     }
+    {% endraw %}
     ```
 
     Click **Save**.