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
This commit is contained in:
Blake Erickson
2023-07-28 09:07:53 -06:00
committed by GitHub
parent 9e4c747657
commit a8c504aee4
2 changed files with 56 additions and 1 deletions

View File

@ -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