mirror of
https://github.com/discourse/discourse.git
synced 2025-01-31 03:09:29 +08:00
Strip leading and trailing slug punctuation.
This commit is contained in:
parent
415f810089
commit
ee8d68842e
|
@ -23,6 +23,7 @@ module Slug
|
||||||
str.gsub!(/[^a-z0-9 -]/, '')
|
str.gsub!(/[^a-z0-9 -]/, '')
|
||||||
str.gsub!(/\s+/, '-')
|
str.gsub!(/\s+/, '-')
|
||||||
str.gsub!(/\-+/, '-')
|
str.gsub!(/\-+/, '-')
|
||||||
|
str.gsub!(/^-|-$/, '')
|
||||||
|
|
||||||
str
|
str
|
||||||
end
|
end
|
||||||
|
|
|
@ -27,6 +27,13 @@ describe Slug do
|
||||||
Slug.for("a....b.....c").should == "a-b-c"
|
Slug.for("a....b.....c").should == "a-b-c"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'strips trailing punctuation' do
|
||||||
|
Slug.for("hello...").should == "hello"
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'strips leading punctuation' do
|
||||||
|
Slug.for("...hello").should == "hello"
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user