Skip to content

Commit

Permalink
[#2669] Fix title munge resulting in multiple dashes.
Browse files Browse the repository at this point in the history
  • Loading branch information
David Read committed Oct 6, 2015
1 parent 85108d8 commit b847f7f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ckan/lib/munge.py
Expand Up @@ -34,7 +34,7 @@ def munge_title_to_name(name):
# take out not-allowed characters
name = re.sub('[^a-zA-Z0-9-_]', '', name).lower()
# remove doubles
name = re.sub('--', '-', name)
name = re.sub('-+', '-', name)
# remove leading or trailing hyphens
name = name.strip('-')
# if longer than max_length, keep last word if a year
Expand Down
9 changes: 5 additions & 4 deletions ckan/tests/lib/test_munge.py
Expand Up @@ -104,14 +104,14 @@ class TestMungeTitleToName(object):
# (original, expected)
munge_list = [
('unchanged', 'unchanged'),
('some spaces here', 'some-spaces-here'),
('some spaces here &here', 'some-spaces-here-here'),
('s', 's_'), # too short
('random:other%character&', 'random-othercharacter'),
(u'u with umlaut \xfc', 'u-with-umlaut-u'),
('reallylong' * 12, 'reallylong' * 9 + 'reall'),
('reallylong' * 12 + ' - 2012', 'reallylong' * 9 + '-2012'),
('10cm - 50cm Near InfraRed (NI) Digital Aerial Photography (AfA142)',
'10cm--50cm-near-infrared-ni-digital-aerial-photography-afa142')
'10cm-50cm-near-infrared-ni-digital-aerial-photography-afa142')
]

def test_munge_title_to_name(self):
Expand All @@ -128,7 +128,8 @@ class TestMungeTag:
('unchanged', 'unchanged'),
('s', 's_'), # too short
('some spaces here', 'some-spaces--here'),
('random:other%character&', 'randomothercharacter')
('random:other%characters&_.here', 'randomothercharactershere'),
('river-water-dashes', 'river-water-dashes'),
]

def test_munge_tag(self):
Expand All @@ -137,7 +138,7 @@ def test_munge_tag(self):
munge = munge_tag(org)
nose_tools.assert_equal(munge, exp)

def test_munge_tag_muliple_pass(self):
def test_munge_tag_multiple_pass(self):
'''Munge a list of tags muliple times gives expected results.'''
for org, exp in self.munge_list:
first_munge = munge_tag(org)
Expand Down

0 comments on commit b847f7f

Please sign in to comment.