From a8c504aee43f2b5589fe6fe3af14012983c393e6 Mon Sep 17 00:00:00 2001 From: Blake Erickson Date: Fri, 28 Jul 2023 09:07:53 -0600 Subject: [PATCH] FIX: Internal oneboxes with github links (#22829) Internal oneboxes to posts that contained oneboxed github links to commits or PRs with long enough commit messages to have the `show-more` and the `excerpt hidden` classes in their html were being stripped of their content resulting in empty internal oneboxes. see: https://meta.discourse.org/t/269436 This fixes a regression introduced in: 0b3cf83e3c7d03c2dcd54f86de60efe32f385a44 --- lib/excerpt_parser.rb | 6 +++- spec/lib/excerpt_parser_spec.rb | 51 +++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/lib/excerpt_parser.rb b/lib/excerpt_parser.rb index 5125135fccf..5d9c9cabe31 100644 --- a/lib/excerpt_parser.rb +++ b/lib/excerpt_parser.rb @@ -114,7 +114,11 @@ class ExcerptParser < Nokogiri::XML::SAX::Document @in_quote = !@keep_onebox_source if attributes.include?(%w[class source]) when "div", "span" attributes = Hash[*attributes.flatten] - if attributes["class"]&.include?("excerpt") + + # Only match "excerpt" class if it does specifically equal "excerpt + # hidden" in order to prevent internal links with GitHub oneboxes from + # being empty https://meta.discourse.org/t/269436 + if attributes["class"]&.include?("excerpt") && !attributes["class"]&.match?("excerpt hidden") @excerpt = +"" @current_length = 0 @start_excerpt = true diff --git a/spec/lib/excerpt_parser_spec.rb b/spec/lib/excerpt_parser_spec.rb index 5a6e494df06..3613a944c7e 100644 --- a/spec/lib/excerpt_parser_spec.rb +++ b/spec/lib/excerpt_parser_spec.rb @@ -110,6 +110,57 @@ RSpec.describe ExcerptParser do The first paragraph of this pinned topic will be … HTML end + + it "keeps the content for internal oneboxes that contain github oneboxes" do + html = <<~HTML.strip +

Another commit to test out.

+

This time this commit has a longer commit message.

+ + HTML + expect(ExcerptParser.get_excerpt(html, 100, keep_onebox_body: false)).to eq(<<~HTML.strip) + Another commit to test out. \nThis time this commit has a longer commit message. + HTML + end end describe "keep_quotes parameter" do