From 65a90d10931276ded31f096cb34a2b006be7080d Mon Sep 17 00:00:00 2001 From: Bilka Date: Wed, 20 May 2026 22:55:09 +0200 Subject: [PATCH] AO3-7476 Fix that text-only bylines for anon works could contain HTML --- app/helpers/byline_helper.rb | 5 +++-- spec/helpers/byline_helper_spec.rb | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/helpers/byline_helper.rb b/app/helpers/byline_helper.rb index 20977a9b2eb..50d523e0917 100644 --- a/app/helpers/byline_helper.rb +++ b/app/helpers/byline_helper.rb @@ -10,12 +10,13 @@ def byline(creation, options = {}) # A plain text version of the byline, for when we don't want to deliver a linkified version. def text_byline(creation, options = {}) + only_path = false + if creation.respond_to?(:anonymous?) && creation.anonymous? anon_byline = t("byline_helper.anonymous_byline") - anon_byline = t("byline_helper.anonymous_with_name_byline_html", pseud_byline: non_anonymous_byline(creation)) if anonymous_with_name?(options, creation) + anon_byline = t("byline_helper.anonymous_with_name_byline_html", pseud_byline: byline_text(creation, only_path, text_only: true)) if anonymous_with_name?(options, creation) anon_byline else - only_path = false byline_text(creation, only_path, text_only: true) end end diff --git a/spec/helpers/byline_helper_spec.rb b/spec/helpers/byline_helper_spec.rb index 904388eb213..fc2e58752fb 100644 --- a/spec/helpers/byline_helper_spec.rb +++ b/spec/helpers/byline_helper_spec.rb @@ -21,4 +21,18 @@ end end end + + describe "#text_byline" do + let(:user) { create(:user, login: "Joe") } + let(:work) { create(:work, authors: [user.default_pseud], collections: [create(:anonymous_collection)]) } + + before do + allow(helper).to receive(:logged_in_as_admin?).and_return(true) + end + + it "includes no links for partially anonymous byline shown to admins" do + expect(helper.text_byline(work)).to_not include("href") + expect(helper.text_byline(work)).to eq("Anonymous [Joe]") + end + end end