diff options
author | Bebleo <james.warne@outlook.com> | 2020-04-19 05:42:12 -0400 |
---|---|---|
committer | David Lord <davidism@gmail.com> | 2021-01-30 06:25:03 -0800 |
commit | d504e1d1e2798d7b4661462b9ef4cd77dd270ff9 (patch) | |
tree | 7b97d883edb56768cc5d72351dfe9f8946dff61d /tests | |
parent | c3b34a06f340234939df5ad77bbe6327ca7fc3f0 (diff) | |
download | jinja2-d504e1d1e2798d7b4661462b9ef4cd77dd270ff9.tar.gz |
Improve and extend urlize
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_filters.py | 23 | ||||
-rw-r--r-- | tests/test_regression.py | 9 |
2 files changed, 32 insertions, 0 deletions
diff --git a/tests/test_filters.py b/tests/test_filters.py index 8087a24..bf00f06 100644 --- a/tests/test_filters.py +++ b/tests/test_filters.py @@ -337,11 +337,23 @@ class TestFilter: assert tmpl.render() == "FOO" def test_urlize(self, env): + tmpl = env.from_string('{{ "foo example.org bar"|urlize }}') + assert tmpl.render() == ( + 'foo <a href="https://example.org" rel="noopener">' "example.org</a> bar" + ) tmpl = env.from_string('{{ "foo http://www.example.com/ bar"|urlize }}') assert tmpl.render() == ( 'foo <a href="http://www.example.com/" rel="noopener">' "http://www.example.com/</a> bar" ) + tmpl = env.from_string('{{ "foo mailto:email@example.com bar"|urlize }}') + assert tmpl.render() == ( + 'foo <a href="mailto:email@example.com">email@example.com</a> bar' + ) + tmpl = env.from_string('{{ "foo email@example.com bar"|urlize }}') + assert tmpl.render() == ( + 'foo <a href="mailto:email@example.com">email@example.com</a> bar' + ) def test_urlize_rel_policy(self): env = Environment() @@ -361,6 +373,17 @@ class TestFilter: "http://www.example.com/</a> bar" ) + def test_urlize_extra_uri_schemes_parameter(self, env): + tmpl = env.from_string( + '{{ "foo tel:+1-514-555-1234 ftp://localhost bar"|' + 'urlize(extra_uri_schemes=["tel:", "ftp:"]) }}' + ) + assert tmpl.render() == ( + 'foo <a href="tel:+1-514-555-1234" rel="noopener">' + 'tel:+1-514-555-1234</a> <a href="ftp://localhost" rel="noopener">' + "ftp://localhost</a> bar" + ) + def test_wordcount(self, env): tmpl = env.from_string('{{ "foo bar baz"|wordcount }}') assert tmpl.render() == "3" diff --git a/tests/test_regression.py b/tests/test_regression.py index d052f43..21a6d92 100644 --- a/tests/test_regression.py +++ b/tests/test_regression.py @@ -109,6 +109,15 @@ class TestBug: "http://www.example.org/<foo</a>" ) + def test_urlize_filter_closing_punctuation(self, env): + tmpl = env.from_string( + '{{ "(see http://www.example.org/?page=subj_<desc.h>)"|urlize }}' + ) + assert tmpl.render() == ( + '(see <a href="http://www.example.org/?page=subj_<desc.h>" ' + 'rel="noopener">http://www.example.org/?page=subj_<desc.h></a>)' + ) + def test_loop_call_loop(self, env): tmpl = env.from_string( """ |