mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
Move logic to reject slugs that are just numbers into the slug module
This commit is contained in:
parent
7d5c313456
commit
b82a5dfd56
3 changed files with 10 additions and 4 deletions
|
@ -85,9 +85,6 @@ class Category < ActiveRecord::Base
|
|||
if name.present?
|
||||
self.slug = Slug.for(name)
|
||||
|
||||
# Reject slugs that only contain numbers, because that's indistinguishable from an id.
|
||||
self.slug = '' unless self.slug =~ /[^\d]/
|
||||
|
||||
return if self.slug.blank?
|
||||
|
||||
# If a category with that slug already exists, set the slug to nil so the category can be found
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
module Slug
|
||||
|
||||
def self.for(string)
|
||||
string.parameterize.gsub("_", "-")
|
||||
slug = string.parameterize.gsub("_", "-")
|
||||
slug =~ /[^\d]/ ? slug : '' # Reject slugs that only contain numbers, because they would be indistinguishable from id's.
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -43,5 +43,13 @@ describe Slug do
|
|||
Slug.for("o_o_o").should == "o-o-o"
|
||||
end
|
||||
|
||||
it "doesn't generate slugs that are just numbers" do
|
||||
Slug.for('123').should be_blank
|
||||
end
|
||||
|
||||
it "doesn't generate slugs that are just numbers" do
|
||||
Slug.for('電車男 2').should be_blank
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue