Why does my site still generate encoded slug even if SiteSetting.slug_generation_method = none

AI-generated summary

topological reports a bug where their Discourse site continues generating encoded slugs for new topics even after setting SiteSetting.slug_generation_method to none. This occurs inconsistently — not for all topics, but some — and persists despite attempts to manually reset slugs via Topic.update_all. Additionally, topological notes that accessing topics with encoded slugs triggers infinite redirects (ERR_TOO_MANY_REDIRECTS), due to slugs_do_not_match returning true when comparing the URL slug with the topic’s stored slug. The issue stems from the slug generation logic not respecting the none setting, leading to mismatched slug comparisons and redirect loops. The log shows a redirect from a decoded Chinese slug to another encoded slug, confirming the system is still treating slugs as encoded despite the setting. The root cause appears to be that slugs are being generated or preserved in encoded form even after the setting change, causing routing inconsistencies.

Some days before, I set SiteSetting.slug_generation_method to encoded, trying to start a chat channel (but not enable chat plugin at all). I see the url is ugly in Chinese locale, so I SiteSetting.slug_generation_method back to none.

However, the site is still generating slug in new topics (not all, but a few). I have no idea what’s wrong with this. I tried to Topic.update_all(slug: "topic") or Topic.update_all(slug: nil) to refresh slug, but still some topics’ slugs are encoded title.

1 Like

Another problem is that I cannot enter a topic with encoded slug , getting ERR_TOO_MANY_REDIRECTS. This kind of topics with encoded slug are generated after I set SiteSetting.slug_generation_method to none.

The log shows

Started GET "/t/%E6%88%91%E4%B9%9F%E8%83%BD%E6%89%BE%E5%88%B0%E5%B1%9E%E4%BA%8E%E6%88%91%E7%9A%84%E9%98%B3%E5%85%89%E5%A4%A7%E7%94%B7%E5%AD%A9%E5%90%97/112562/39" for 10.182.185.76 at 2022-11-23 19:35:09 +0800
  Rendered text template (Duration: 0.0ms | Allocations: 1)
Processing by TopicsController#show as HTML
  Parameters: {"slug"=>"我也能找到属于我的阳光大男孩吗", "topic_id"=>"112562", "post_number"=>"39"}
Redirected to https://my-domain/t/%E8%BF%98%E6%9C%89%E4%B8%8D%E5%88%B040%E5%A4%A9%EF%BC%8C2022%E5%B9%B4%E5%B0%B1%E7%BB%93%E6%9D%9F%E4%BA%86%EF%BC%8C%E8%AF%B7%E7%94%A8%E4%B8%80%E4%B8%AA%E5%AD%97%E6%88%96%E8%80%85%E8%AF%8D%E8%AF%AD%E6%9D%A5%E8%AF%84%E4%BB%B7%E5%AE%83%E5%90%A7/112489
Completed 301 Moved Permanently in 176ms (ActiveRecord: 0.0ms | Allocations: 19880)

I read the code, maybe slugs_do_not_match return true, as %E6%88%91%E4%B9%9F%E8%83%BD%E6%89%BE%E5%88%B0%E5%B1%9E%E4%BA%8E%E6%88%91%E7%9A%84%E9%98%B3%E5%85%89%E5%A4%A7%E7%94%B7%E5%AD%A9%E5%90%97 != 我也能找到属于我的阳光大男孩吗。And this cause a redirect.

  def slugs_do_not_match
    if SiteSetting.slug_generation_method != "encoded"
      params[:slug] && @topic_view.topic.slug != params[:slug]
    else
      params[:slug] && CGI.unescape(@topic_view.topic.slug) != params[:slug]
    end
  end

So the problem is the same, i.e., why my site generates encoded slug when SiteSetting.slug_generation_method is already none.