Skip to content

Commit 6de860b

Browse files
committedJul 11, 2015
Better slugify tests; remove dupliate banned character
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
1 parent 50f92ad commit 6de860b

File tree

2 files changed

+42
-13
lines changed

2 files changed

+42
-13
lines changed
 

‎nikola/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ def slugify(value, force=False):
740740
# We still replace some characters, though. In particular, we need
741741
# to replace ? and #, which should not appear in URLs, and some
742742
# Windows-unsafe characters. This list might be even longer.
743-
rc = '/\\?#"\'\r\n\t*:<>|"'
743+
rc = '/\\?#"\'\r\n\t*:<>|'
744744

745745
for c in rc:
746746
value = value.replace(c, '-')

‎tests/test_slugify.py

+41-12
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,65 @@
11
# -*- coding: utf-8 -*-
2+
3+
u"""Test slugify."""
4+
5+
from __future__ import unicode_literals
26
import nikola.utils
37

8+
49
def test_ascii():
5-
o = nikola.utils.slugify(u'abcdef')
6-
assert o == u'abcdef'
10+
"""Test an ASCII-only string."""
11+
o = nikola.utils.slugify(u'hello')
12+
assert o == u'hello'
713
assert isinstance(o, nikola.utils.unicode_str)
814

15+
916
def test_ascii_dash():
10-
o = nikola.utils.slugify(u'abc-def')
11-
assert o == u'abc-def'
17+
"""Test an ASCII string, with dashes."""
18+
o = nikola.utils.slugify(u'hello-world')
19+
assert o == u'hello-world'
20+
assert isinstance(o, nikola.utils.unicode_str)
21+
22+
23+
def test_ascii_fancy():
24+
"""Test an ASCII string, with fancy characters."""
25+
o = nikola.utils.slugify(u'The quick brown fox jumps over the lazy dog!-123.456')
26+
assert o == u'the-quick-brown-fox-jumps-over-the-lazy-dog-123456'
1227
assert isinstance(o, nikola.utils.unicode_str)
1328

29+
1430
def test_pl():
15-
o = nikola.utils.slugify(u'ąbćdef')
16-
assert o == u'abcdef'
31+
"""Test a string with Polish diacritical characters."""
32+
o = nikola.utils.slugify(u'zażółćgęśląjaźń')
33+
assert o == u'zazolcgeslajazn'
1734
assert isinstance(o, nikola.utils.unicode_str)
1835

36+
1937
def test_pl_dash():
20-
o = nikola.utils.slugify(u'ąbć-def')
21-
assert o == u'abc-def'
38+
"""Test a string with Polish diacritical characters and dashes."""
39+
o = nikola.utils.slugify(u'zażółć-gęślą-jaźń')
40+
assert o == u'zazolc-gesla-jazn'
41+
42+
43+
def test_pl_fancy():
44+
"""Test a string with Polish diacritical characters and fancy characters."""
45+
o = nikola.utils.slugify(u'Zażółć gęślą jaźń!-123.456')
46+
assert o == u'zazolc-gesla-jazn-123456'
2247
assert isinstance(o, nikola.utils.unicode_str)
2348

49+
2450
def test_disarmed():
51+
"""Test disarmed slugify."""
2552
nikola.utils.USE_SLUGIFY = False
26-
o = nikola.utils.slugify(u'ąbć-def')
27-
assert o == u'ąbć-def'
53+
o = nikola.utils.slugify(u'Zażółć gęślą jaźń!-123.456')
54+
assert o == u'Zażółć gęślą jaźń!-123.456'
2855
assert isinstance(o, nikola.utils.unicode_str)
2956
nikola.utils.USE_SLUGIFY = True
3057

58+
3159
def test_disarmed_weird():
60+
"""Test disarmed slugify with banned characters."""
3261
nikola.utils.USE_SLUGIFY = False
33-
o = nikola.utils.slugify(u'ąbć-def "Hello World"?#H<e>l/l\\o:W\'o\rr*l\td|!\n')
34-
assert o == u'ąbć-def -Hello World---H-e-l-l-o-W-o-r-l-d-!-'
62+
o = nikola.utils.slugify(u'Zażółć gęślą jaźń!-123.456 "Hello World"?#H<e>l/l\\o:W\'o\rr*l\td|!\n')
63+
assert o == u'Zażółć gęślą jaźń!-123.456 -Hello World---H-e-l-l-o-W-o-r-l-d-!-'
3564
assert isinstance(o, nikola.utils.unicode_str)
3665
nikola.utils.USE_SLUGIFY = True

0 commit comments

Comments
 (0)
Please sign in to comment.