diff --git a/lib/slug.rb b/lib/slug.rb index 9678130ed24..c4fe8fdfb0f 100644 --- a/lib/slug.rb +++ b/lib/slug.rb @@ -23,6 +23,7 @@ module Slug str.gsub!(/[^a-z0-9 -]/, '') str.gsub!(/\s+/, '-') str.gsub!(/\-+/, '-') + str.gsub!(/^-|-$/, '') str end diff --git a/spec/components/slug_spec.rb b/spec/components/slug_spec.rb index 6111b73710e..fde5ebd8e33 100644 --- a/spec/components/slug_spec.rb +++ b/spec/components/slug_spec.rb @@ -27,6 +27,13 @@ describe Slug do Slug.for("a....b.....c").should == "a-b-c" end + it 'strips trailing punctuation' do + Slug.for("hello...").should == "hello" + end + + it 'strips leading punctuation' do + Slug.for("...hello").should == "hello" + end end