Skip to content

A platform for community discussion. Free, open, simple.

FIX: Regression with numeric tags in RSS feed URL generation (#39113)

Penar Musarajb6202b464dc5
diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb
index 3086e7dc297..f6a672c7e9f 100644
--- a/app/controllers/tags_controller.rb
+++ b/app/controllers/tags_controller.rb
@@ -210,6 +210,9 @@ class TagsController < ::ApplicationController
@list.more_topics_url = construct_url_with(:next, list_opts)
@list.prev_topics_url = construct_url_with(:prev, list_opts)
@rss = "tag"
+ @rss_description = "tag"
+ @rss_link = "#{@tag.full_url}.rss" if @tag
+
@title = I18n.t("rss_by_tag", tag: tag_params.join(" & "))
@description_meta = Tag.where(name: @tag_name).pick(:description) || @title
@@ -557,12 +560,20 @@ class TagsController < ::ApplicationController
private
def fetch_tag(raise_not_found: true)
- @tag =
- if params[:tag_id].present?
- Tag.find_by(id: params[:tag_id])
- elsif params[:tag_name].present?
- Tag.find_by_name(params[:tag_name].force_encoding("UTF-8"))
+ if params[:tag_id].present?
+ # Try finding by ID first
+ @tag = Tag.find_by(id: params[:tag_id])
+
+ # For numeric tag names on legacy routes, fallback to finding by name
+ if !@tag
+ @tag = Tag.find_by_name(params[:tag_id])
+ # Track that we found the tag by name, not ID, to avoid redirecting
+ @tag_found_by_name = true if @tag
end
+ elsif params[:tag_name].present?
+ @tag = Tag.find_by_name(params[:tag_name].force_encoding("UTF-8"))
+ end
+
raise Discourse::NotFound if @tag ? !guardian.can_see_tag?(@tag) : raise_not_found
@tag
end
@@ -596,6 +607,8 @@ class TagsController < ::ApplicationController
return false if request.format.json?
# intersection routes use tag_name, not tag_slug/tag_id - don't redirect
return false if params[:additional_tag_names].present?
+ # don't redirect if we found the tag by name (numeric tag name on legacy route)
+ return false if @tag_found_by_name
if params[:tag_id].present?
# new format - redirect if slug doesn't match
diff --git a/app/views/list/list.erb b/app/views/list/list.erb
index 60b6c4631bb..30a3f9d31a3 100644
--- a/app/views/list/list.erb
+++ b/app/views/list/list.erb
@@ -133,7 +133,11 @@
<% if @rss %>
<% content_for :head do %>
<%= auto_discovery_link_tag(:rss, "#{Discourse.base_url}/posts.rss", title: I18n.t("rss_description.posts")) %>
- <%= auto_discovery_link_tag(:rss, { action: "#{@rss}_feed", params: @params || {} }, title: I18n.t("rss_description.#{@rss_description}")) %>
+ <% if @rss_link %>
+ <%= auto_discovery_link_tag(:rss, @rss_link, title: I18n.t("rss_description.#{@rss_description}")) %>
+ <% else %>
+ <%= auto_discovery_link_tag(:rss, { action: "#{@rss}_feed", params: @params || {} }, title: I18n.t("rss_description.#{@rss_description}")) %>
+ <% end %>
<% end %>
<% end %>
diff --git a/spec/requests/tags_controller_spec.rb b/spec/requests/tags_controller_spec.rb
index 73d9993b839..6faf6273d7a 100644
--- a/spec/requests/tags_controller_spec.rb
+++ b/spec/requests/tags_controller_spec.rb
@@ -511,6 +511,24 @@ RSpec.describe TagsController do
expect(response.parsed_body["topic_list"]["topics"].length).to eq(1)
end
+ it "handles numeric tag names via legacy /tag/:tag_name route" do
+ numeric_tag = Fabricate(:tag, name: "6309")
+ Fabricate(:topic, tags: [numeric_tag])
+
+ get "/tag/6309"
+ expect(response.status).to eq(200)
+ expect(response.body).not_to include("ActionView::Template::Error")
+ end
+
+ it "handles numeric tag names via legacy /tag/:tag_name route with filters" do
+ numeric_tag = Fabricate(:tag, name: "6309")
+ Fabricate(:topic, tags: [numeric_tag])
+
+ get "/tag/6309/l/latest"
+ expect(response.status).to eq(200)
+ expect(response.body).not_to include("ActionView::Template::Error")
+ end
+
context "with a category in the path" do
fab!(:topic_in_category) { Fabricate(:topic, tags: [tag], category: category) }