Loading django/utils/html.py +6 −6 Original line number Diff line number Diff line Loading @@ -126,13 +126,13 @@ strip_tags = allow_lazy(strip_tags) def remove_tags(html, tags): """Returns the given HTML with given tags removed.""" tags = [re.escape(tag) for tag in tags.split()] tags_re = u'(%s)' % u'|'.join(tags) starttag_re = re.compile(ur'<%s(/?>|(\s+[^>]*>))' % tags_re, re.U) endtag_re = re.compile(u'</%s>' % tags_re) html = starttag_re.sub(u'', html) html = endtag_re.sub(u'', html) tags_re = '(%s)' % '|'.join(tags) starttag_re = re.compile(r'<%s(/?>|(\s+[^>]*>))' % tags_re, re.U) endtag_re = re.compile('</%s>' % tags_re) html = starttag_re.sub('', html) html = endtag_re.sub('', html) return html remove_tags = allow_lazy(remove_tags, unicode) remove_tags = allow_lazy(remove_tags, six.text_type) def strip_spaces_between_tags(value): """Returns the given HTML with spaces between tags removed.""" Loading django/utils/text.py +3 −3 Original line number Diff line number Diff line Loading @@ -391,7 +391,7 @@ def slugify(value): underscores) and converts spaces to hyphens. Also strips leading and trailing whitespace. """ value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore') value = unicode(re.sub('[^\w\s-]', '', value).strip().lower()) value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode('ascii') value = re.sub('[^\w\s-]', '', value).strip().lower() return mark_safe(re.sub('[-\s]+', '-', value)) slugify = allow_lazy(slugify, unicode) slugify = allow_lazy(slugify, six.text_type) tests/regressiontests/utils/text.py +2 −2 Original line number Diff line number Diff line Loading @@ -116,8 +116,8 @@ class TestUtilsText(SimpleTestCase): def test_slugify(self): items = ( (u'Hello, World!', 'hello-world'), (u'spam & eggs', 'spam-eggs'), ('Hello, World!', 'hello-world'), ('spam & eggs', 'spam-eggs'), ) for value, output in items: self.assertEqual(text.slugify(value), output) Loading
django/utils/html.py +6 −6 Original line number Diff line number Diff line Loading @@ -126,13 +126,13 @@ strip_tags = allow_lazy(strip_tags) def remove_tags(html, tags): """Returns the given HTML with given tags removed.""" tags = [re.escape(tag) for tag in tags.split()] tags_re = u'(%s)' % u'|'.join(tags) starttag_re = re.compile(ur'<%s(/?>|(\s+[^>]*>))' % tags_re, re.U) endtag_re = re.compile(u'</%s>' % tags_re) html = starttag_re.sub(u'', html) html = endtag_re.sub(u'', html) tags_re = '(%s)' % '|'.join(tags) starttag_re = re.compile(r'<%s(/?>|(\s+[^>]*>))' % tags_re, re.U) endtag_re = re.compile('</%s>' % tags_re) html = starttag_re.sub('', html) html = endtag_re.sub('', html) return html remove_tags = allow_lazy(remove_tags, unicode) remove_tags = allow_lazy(remove_tags, six.text_type) def strip_spaces_between_tags(value): """Returns the given HTML with spaces between tags removed.""" Loading
django/utils/text.py +3 −3 Original line number Diff line number Diff line Loading @@ -391,7 +391,7 @@ def slugify(value): underscores) and converts spaces to hyphens. Also strips leading and trailing whitespace. """ value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore') value = unicode(re.sub('[^\w\s-]', '', value).strip().lower()) value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode('ascii') value = re.sub('[^\w\s-]', '', value).strip().lower() return mark_safe(re.sub('[-\s]+', '-', value)) slugify = allow_lazy(slugify, unicode) slugify = allow_lazy(slugify, six.text_type)
tests/regressiontests/utils/text.py +2 −2 Original line number Diff line number Diff line Loading @@ -116,8 +116,8 @@ class TestUtilsText(SimpleTestCase): def test_slugify(self): items = ( (u'Hello, World!', 'hello-world'), (u'spam & eggs', 'spam-eggs'), ('Hello, World!', 'hello-world'), ('spam & eggs', 'spam-eggs'), ) for value, output in items: self.assertEqual(text.slugify(value), output)