Skip to content

Commit

Permalink
Turn "fööbär" into "foobar", not "f-o-ob-ar". As a desired side-effec…
Browse files Browse the repository at this point in the history
…t, "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.
  • Loading branch information
henrik committed May 22, 2008
1 parent 5612167 commit c5cd3ad
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/permalink_fu.rb
Expand Up @@ -12,10 +12,10 @@ class << self

def escape(str)
s = ((translation_to && translation_from) ? Iconv.iconv(translation_to, translation_from, str) : str).to_s
s.gsub!(/\W+/, ' ') # all non-word chars to spaces
s.gsub!(/[^\w -]+/, '') # strip unwanted characters
s.strip! # ohh la la
s.downcase! #
s.gsub!(/\ +/, '-') # spaces to dashes, preferred separator char everywhere
s.gsub!(/[ -]+/, '-') # separate by single dashes
s
end
end
Expand Down
5 changes: 3 additions & 2 deletions test/permalink_fu_test.rb
Expand Up @@ -132,10 +132,11 @@ class MockModelExtra < BaseModel

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

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

0 comments on commit c5cd3ad

Please sign in to comment.