Skip to content

Commit c5cd3ad

Browse files
committed
Turn "fööbär" into "foobar", not "f-o-ob-ar". As a desired side-effect, "foo!!1" becomes "foo1" rather than "foo-1".
This is under OS X, by the way. I believe iconv can behave slightly differently on different platforms.
1 parent 5612167 commit c5cd3ad

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

lib/permalink_fu.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ class << self
1212

1313
def escape(str)
1414
s = ((translation_to && translation_from) ? Iconv.iconv(translation_to, translation_from, str) : str).to_s
15-
s.gsub!(/\W+/, ' ') # all non-word chars to spaces
15+
s.gsub!(/[^\w -]+/, '') # strip unwanted characters
1616
s.strip! # ohh la la
1717
s.downcase! #
18-
s.gsub!(/\ +/, '-') # spaces to dashes, preferred separator char everywhere
18+
s.gsub!(/[ -]+/, '-') # separate by single dashes
1919
s
2020
end
2121
end

test/permalink_fu_test.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,11 @@ class MockModelExtra < BaseModel
132132

133133
class PermalinkFuTest < Test::Unit::TestCase
134134
@@samples = {
135-
'This IS a Tripped out title!!.!1 (well/ not really)' => 'this-is-a-tripped-out-title-1-well-not-really',
135+
'This IS a Tripped out title!!.!1 (well/ not really)' => 'this-is-a-tripped-out-title1-well-not-really',
136136
'////// meph1sto r0x ! \\\\\\' => 'meph1sto-r0x',
137137
'āčēģīķļņū' => 'acegiklnu',
138-
'中文測試 chinese text' => 'chinese-text'
138+
'中文測試 chinese text' => 'chinese-text',
139+
'fööbär' => 'foobar'
139140
}
140141

141142
@@extra = { 'some-)()()-ExtRa!/// .data==?> to \/\/test' => 'some-extra-data-to-test' }

0 commit comments

Comments
 (0)