Improved regex in strip_tags · d7504a3 · django/django
Description: django - The web framework for perfectionists with deadlines.

- claudep

Browse code

Improved regex in strip_tags

    Thanks Pablo Recio for the report. Refs #19237.

commit d7504a3d7b8645bdb979bab7ded0e9a9b6dccd0e 1 parent afa3e16
claudep authored February 06, 2013
2  django/utils/html.py
show inline notes
View file @ `d7504a3`

... | ... | @@ -33,7 +33,7 @@
33 | 33 | html_gunk_re = re.compile(r'(?:<br clear="all">|<i><\/i>|<b><\/b>|<em><\/em>|<strong><\/strong>|<\/?smallcaps>|<\/?uppercase>)', re.IGNORECASE)
34 | 34 | hard_coded_bullets_re = re.compile(r'((?:<p>(?:%s).*?[a-zA-Z].*?</p>\s*)+)' % '|'.join([re.escape(x) for x in DOTS]), re.DOTALL)
35 | 35 | trailing_empty_content_re = re.compile(r'(?:<p>(?:&nbsp;|\s|<br \/>)*?</p>\s*)+\Z')
36 |  | -strip_tags_re = re.compile(r'</?\S([^=]*=(\s*"[^"]*"|\s*\'[^\']*\'|\S*)|[^>])*?>', re.IGNORECASE)
| 36 | +strip_tags_re = re.compile(r'</?\S([^=>]*=(\s*"[^"]*"|\s*\'[^\']*\'|\S*)|[^>])*?>', re.IGNORECASE)
37 | 37 |
38 | 38 |
39 | 39 | def escape(text):

1  tests/regressiontests/utils/html.py
show inline notes
View file @ `d7504a3`

... | ... | @@ -68,6 +68,7 @@ def test_strip_tags(self):
68 | 68 | ('a<p onclick="alert(\'<test>\')">b</p>c', 'abc'),
69 | 69 | ('a<p a >b</p>c', 'abc'),
70 | 70 | ('d<a:b c:d>e</p>f', 'def'),
| 71 | + ('<strong>foo</strong><a href="http://example.com">bar</a>', 'foobar'),
71 | 72 | )
72 | 73 | for value, output in items:
73 | 74 | self.check_output(f, value, output)

## 0 notes on commit `d7504a3` Show line notes below

- Write
- Preview

Comments are parsed with GitHub Flavored Markdown

Attach images by dragging & dropping them or choose an image Uploading your images now… Unfortunately we don't support that file type yet. Try image files less than 5MB. This browser doesn't support image attachments. Something went really wrong and we can't process that image.

claudep commented April 01, 2013

Nothing to preview

Tip: You can also add notes to lines in a file. Hover to the left of a line to make a note

You only receive notifications for this thread when you participate or are @mentioned.

Test string that has not been stripped.