Navigation Menu

Skip to content

Commit

Permalink
FIX: Make category updates slug validation idempotent
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Brown <supermathie@gmail.com>
  • Loading branch information
xfalcox and Supermathie committed Oct 21, 2019
1 parent 3ad07aa commit 2e73985
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/models/category.rb
Expand Up @@ -285,6 +285,7 @@ def ensure_slug

if slug.present?
# santized custom slug
slug = SiteSetting.slug_generation_method == 'encoded' ? CGI.unescape(self.slug) : self.slug
self.slug = Slug.sanitize(slug)
errors.add(:slug, 'is already in use') if duplicate_slug?
else
Expand Down
6 changes: 6 additions & 0 deletions spec/models/category_spec.rb
Expand Up @@ -316,6 +316,12 @@
expect(@category.slug).to eq("%E6%B5%8B%E8%AF%95")
expect(@category.slug_for_url).to eq("%E6%B5%8B%E8%AF%95")
end

it "keeps the slug" do
@category.save
expect(@category.slug).to eq("%E6%B5%8B%E8%AF%95")
expect(@category.slug_for_url).to eq("%E6%B5%8B%E8%AF%95")
end
end
end

Expand Down

1 comment on commit 2e73985

@discoursereviewbot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.