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