mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
FIX: If a prettified slug is a number, return defaultt (#8554)
Meta thread: https://meta.discourse.org/t/sending-a-pm-with-the-following-title-causes-an-error/135654/3 We had an issue where if someone sent a PM with crazy characters that are stripped and we end up with only a number, the topic redirect errored because the slug was a number. so instead we return the default as well if the slug is a number after prettification
This commit is contained in:
@ -20,7 +20,7 @@ module Slug
|
||||
when :none then self.none_generator(string)
|
||||
end
|
||||
slug = self.prettify_slug(slug, max_length: max_length)
|
||||
slug.blank? ? default : slug
|
||||
(slug.blank? || slug_is_only_numbers?(slug)) ? default : slug
|
||||
end
|
||||
|
||||
def self.sanitize(string, downcase: false, max_length: MAX_LENGTH)
|
||||
@ -30,9 +30,13 @@ module Slug
|
||||
|
||||
private
|
||||
|
||||
def self.slug_is_only_numbers?(slug)
|
||||
(slug =~ /[^\d]/).blank?
|
||||
end
|
||||
|
||||
def self.prettify_slug(slug, max_length:)
|
||||
# Reject slugs that only contain numbers, because they would be indistinguishable from id's.
|
||||
slug = (slug =~ /[^\d]/ ? slug : '')
|
||||
slug = (slug_is_only_numbers?(slug) ? '' : slug)
|
||||
|
||||
slug
|
||||
.tr("_", "-")
|
||||
|
Reference in New Issue
Block a user