mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 11:44:49 +08:00
FIX: category custom slug can't be set when generation method is none
This commit is contained in:
parent
51d82fc25d
commit
4c00eef8b5
|
@ -207,7 +207,7 @@ SQL
|
|||
|
||||
if slug.present?
|
||||
# santized custom slug
|
||||
self.slug = Slug.for(slug, '')
|
||||
self.slug = Slug.sanitize(slug)
|
||||
errors.add(:slug, 'is already in use') if duplicate_slug?
|
||||
else
|
||||
# auto slug
|
||||
|
|
|
@ -13,6 +13,10 @@ module Slug
|
|||
slug.blank? ? default : slug
|
||||
end
|
||||
|
||||
def self.sanitize(string)
|
||||
self.encoded_generator(string)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.ascii_generator(string)
|
||||
|
|
|
@ -232,15 +232,21 @@ describe CategoriesController do
|
|||
it 'accepts valid custom slug' do
|
||||
xhr :put, :update_slug, category_id: @category.id, slug: 'valid-slug'
|
||||
expect(response).to be_success
|
||||
category = Category.find(@category.id)
|
||||
expect(category.slug).to eq('valid-slug')
|
||||
expect(@category.reload.slug).to eq('valid-slug')
|
||||
end
|
||||
|
||||
it 'accepts not well formed custom slug' do
|
||||
xhr :put, :update_slug, category_id: @category.id, slug: ' valid slug'
|
||||
expect(response).to be_success
|
||||
category = Category.find(@category.id)
|
||||
expect(category.slug).to eq('valid-slug')
|
||||
expect(@category.reload.slug).to eq('valid-slug')
|
||||
end
|
||||
|
||||
it 'accepts and sanitize custom slug when the slug generation method is not english' do
|
||||
SiteSetting.slug_generation_method = 'none'
|
||||
xhr :put, :update_slug, category_id: @category.id, slug: ' another !_ slug @'
|
||||
expect(response).to be_success
|
||||
expect(@category.reload.slug).to eq('another-slug')
|
||||
SiteSetting.slug_generation_method = 'ascii'
|
||||
end
|
||||
|
||||
it 'rejects invalid custom slug' do
|
||||
|
|
Loading…
Reference in New Issue
Block a user