discourse/app/jobs/onceoff/fix_encoded_topic_slugs.rb
Rafael dos Santos Silva 76ab0350f1
FIX: Properly encoded slugs when configured to (#8158)
When an admin changes the site setting slug_generation_method to
encoded, we weren't really encoding the slug, but just allowing non-ascii
characters in the slug (unicode).

That brings problems when a user posts a link to topic without the slug, as
our topic controller tries to redirect the user to the correct URL that contains
the slug with unicode characters. Having unicode in the Location header in a
response is a RFC violation and some browsers end up in a redirection loop.

Bug report: https://meta.discourse.org/t/-/125371?u=falco

This commit also checks if a site uses encoded slugs and clear all saved slugs
in the db so they can be regenerated using an onceoff job.
2019-10-11 12:38:16 -03:00

15 lines
321 B
Ruby

# frozen_string_literal: true
module Jobs
class FixEncodedTopicSlugs < ::Jobs::Onceoff
def execute_onceoff(args)
return unless SiteSetting.slug_generation_method == 'encoded'
#Make all slugs nil and let the app regenerate with proper encoded ones
Topic.update_all(slug: nil)
end
end
end