mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-02-17 04:01:29 -05:00
Don't allow category slugs that are numbers
This commit is contained in:
parent
5d444be72b
commit
7d5c313456
2 changed files with 13 additions and 0 deletions
|
@ -85,6 +85,11 @@ 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
|
||||
# another way.
|
||||
category = Category.where(slug: self.slug)
|
||||
|
|
|
@ -104,6 +104,14 @@ describe Category do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'slug would be a number' do
|
||||
let(:category) { Fabricate(:category, name: "電車男 2") }
|
||||
|
||||
it 'creates a blank slug' do
|
||||
category.slug.should be_blank
|
||||
end
|
||||
end
|
||||
|
||||
describe 'after create' do
|
||||
before do
|
||||
@category = Fabricate(:category, name: 'Amazing Category')
|
||||
|
|
Loading…
Reference in a new issue