FIX: Use subfolder-safe url for category in html view (#24595)

Use subfolder-safe url for category in html view
This commit is contained in:
Natalie Tay 2023-11-28 19:08:14 +08:00 committed by GitHub
parent 1eaf774f47
commit 22ce638ec3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View File

@ -8,7 +8,7 @@
<div class="topic-category" itemscope itemtype="http://schema.org/BreadcrumbList">
<% @breadcrumbs.each_with_index do |c, i| %>
<span itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
<a href="<%= Discourse.base_url %><%= c[:url] %>" class="badge-wrapper bullet" itemprop="item">
<a href="<%= @topic_view.topic.category.url %>" class="badge-wrapper bullet" itemprop="item">
<span class='badge-category-bg' style='background-color: #<%= c[:color] %>'></span>
<span class='badge-category clear-badge'>
<span class='category-name' itemprop='name'><%= c[:name] %></span>

View File

@ -4,7 +4,22 @@ require "rails_helper"
require "ostruct"
RSpec.describe "topics/show.html.erb" do
fab!(:topic)
fab!(:category)
fab!(:topic) { Fabricate(:topic, category: category) }
it "uses subfolder-safe category url" do
set_subfolder "/subpath"
topic_view = OpenStruct.new(topic: topic, posts: [])
topic_view.stubs(:summary).returns("")
view.stubs(:crawler_layout?).returns(false)
assign(:topic_view, topic_view)
assign(:breadcrumbs, [{ name: category.name, color: category.color }])
assign(:tags, [])
render template: "topics/show", formats: [:html]
assert_select "a[href='/subpath/c/#{category.slug}/#{category.id}']"
end
it "add nofollow to RSS alternate link for topic" do
topic_view = OpenStruct.new(topic: topic, posts: [])