Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
chrstinalin committed Jan 7, 2025
1 parent 085c766 commit 46209df
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/olympia/devhub/templates/devhub/addons/edit/describe.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% from "devhub/includes/macros.html" import tip, empty_unless, flags, select_cats, markdown_tip, trans_readonly %}
{% from "devhub/includes/macros.html" import tip, empty_unless, flags, select_cats, supported_syntax_tip, trans_readonly %}

<form method="post" action="{{ url('devhub.addons.section', valid_slug, 'describe', 'edit') }}"
id="addon-edit-describe"
Expand Down Expand Up @@ -141,7 +141,7 @@ <h3>
<div class="char-count"
data-for-startswith="{{ main_form.description.auto_id }}_"
data-minlength="{{ main_form.description.field.min_length }}"></div>
{{ markdown_tip() }}
{{ supported_syntax_tip() }}
{% else %}
{% call empty_unless(addon.description) %}
<div id="addon-description" class="prose">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% from "devhub/includes/macros.html" import tip, markdown_tip, empty_unless, flags %}
{% from "devhub/includes/macros.html" import tip, supported_syntax_tip, empty_unless, flags %}

<form method="post"
action="{{ url('devhub.addons.section', addon.slug, 'technical', 'edit') }}">
Expand Down Expand Up @@ -32,7 +32,7 @@ <h3>
{% if editable %}
{{ main_form.developer_comments }}
{{ main_form.developer_comments.errors }}
{{ markdown_tip() }}
{{ supported_syntax_tip() }}
{% else %}
{% call empty_unless(addon.developer_comments) %}
<div id="developer_comments">{{ addon|all_locales('developer_comments', nl2br=True) }}</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% from "devhub/includes/macros.html" import markdown_tip, select_cats %}
{% from "devhub/includes/macros.html" import supported_syntax_tip, select_cats %}
{% from "includes/forms.html" import tip %}
{% extends "devhub/addons/submit/base.html" %}

Expand Down Expand Up @@ -113,7 +113,7 @@ <h3>{{ _('Describe Add-on') }}</h3>
data-for-startswith="{{ describe_form.description.auto_id }}_"
data-minlength="{{ describe_form.description.field.min_length }}"></div>
</div>
{{ markdown_tip() }}
{{ supported_syntax_tip() }}
</div>
{% endif %}
{% if addon.type != amo.ADDON_STATICTHEME %}
Expand Down Expand Up @@ -180,7 +180,7 @@ <h3>{{ _('Describe Add-on') }}</h3>
{{ license_form.text.errors }}
{{ license_form.text.label_tag() }}
{{ license_form.text }}
{{ markdown_tip() }}
{{ supported_syntax_tip() }}
</div>
</div>
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion src/olympia/devhub/templates/devhub/includes/macros.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</p>
{% endmacro %}

{% macro markdown_tip(title=None) %}
{% macro supported_syntax_tip(title=None) %}
<p class="syntax-support">
{# L10n: %s is a list of markdown syntax. #}
<span class="tooltip" title="{% if title %}{{ title }}{% else %}{{
Expand Down
6 changes: 3 additions & 3 deletions src/olympia/devhub/templates/devhub/includes/policy_form.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% from "devhub/includes/macros.html" import tip, markdown_tip %}
{% from "devhub/includes/macros.html" import tip, supported_syntax_tip %}
<tr>
<th>{{ tip(_('End-User License Agreement'),
_('Please note that a EULA is not '
Expand All @@ -13,7 +13,7 @@
{{ policy_form.eula.label }}
</label>
{{ policy_form.eula }}
{{ markdown_tip() }}
{{ supported_syntax_tip() }}
</div>
</td>
</tr>
Expand All @@ -31,7 +31,7 @@
{{ policy_form.privacy_policy.label }}
</label>
{{ policy_form.privacy_policy }}
{{ markdown_tip() }}
{{ supported_syntax_tip() }}
</div>
</td>
</tr>
2 changes: 2 additions & 0 deletions src/olympia/translations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ def clean_localized_string(self):
)
# hack; cleaning breaks blockquotes
text_with_brs = cleaned.replace('&gt;', '>')
# the base syntax of markdown library does not provide abbreviations or fenced code.
# see https://python-markdown.github.io/extensions/
markdown = md.markdown(text_with_brs, extensions=['abbr', 'fenced_code'])

# Keep only the allowed tags and attributes, strip the rest.
Expand Down
48 changes: 48 additions & 0 deletions src/olympia/translations/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from olympia.translations.models import (
LinkifiedTranslation,
NoURLsTranslation,
PurifiedMarkdownTranslation,
PurifiedTranslation,
Translation,
TranslationSequence,
Expand Down Expand Up @@ -701,6 +702,53 @@ def test_external_text_link(self, get_outgoing_url_mock):
assert doc('b')[0].text == 'markup'


class PurifiedMarkdownTranslationTest(TestCase):
def test_output(self):
assert isinstance(PurifiedMarkdownTranslation().__html__(), str)

def test_raw_text(self):
s = ' This is some text '
x = PurifiedMarkdownTranslation(localized_string=s)
assert x.__html__() == 'This is some text'

def test_markdown(self):
s = '__bold text__ or _italics_ <b>not bold</b>'
x = PurifiedMarkdownTranslation(localized_string=s)
assert x.__html__() == '<strong>bold text</strong> or <em>italics</em> &lt;b&gt;not bold&lt;/b&gt;'

def test_html(self):
s = '<script>some naughty xss</script>'
x = PurifiedMarkdownTranslation(localized_string=s)
assert x.__html__() == '&lt;script&gt;some naughty xss&lt;/script&gt;'

def test_internal_link(self):
s = '**markup** [bar](http://addons.mozilla.org/foo)'
x = PurifiedMarkdownTranslation(localized_string=s)
doc = pq(x.__html__())
links = doc('a[href="http://addons.mozilla.org/foo"][rel="nofollow"]')
assert links[0].text == 'bar'
assert doc('strong')[0].text == 'markup'

@patch('olympia.amo.urlresolvers.get_outgoing_url')
def test_external_link(self, get_outgoing_url_mock):
get_outgoing_url_mock.return_value = 'http://external.url'
s = '**markup** [bar](http://example.com)'
x = PurifiedMarkdownTranslation(localized_string=s)
doc = pq(x.__html__())
links = doc('a[href="http://external.url"][rel="nofollow"]')
assert links[0].text == 'bar'
assert doc('strong')[0].text == 'markup'

@patch('olympia.amo.urlresolvers.get_outgoing_url')
def test_external_text_link(self, get_outgoing_url_mock):
get_outgoing_url_mock.return_value = 'http://external.url'
s = '**markup** http://example.com'
x = PurifiedMarkdownTranslation(localized_string=s)
doc = pq(x.__html__())
links = doc('a[href="http://external.url"][rel="nofollow"]')
assert links[0].text == 'http://example.com'
assert doc('strong')[0].text == 'markup'

class LinkifiedTranslationTest(TestCase):
@patch('olympia.amo.urlresolvers.get_outgoing_url')
def test_allowed_tags(self, get_outgoing_url_mock):
Expand Down

0 comments on commit 46209df

Please sign in to comment.