0
0
Fork 0

Change fetch link card service to parse as HTML5 (#31814)

This commit is contained in:
Mike Dalessio 2024-09-09 06:59:42 -04:00 committed by GitHub
parent 9d9901cc5b
commit a0ea2fa3b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 22 additions and 22 deletions

View file

@ -29,7 +29,7 @@ class FetchLinkCardService < BaseService
end
attach_card if @card&.persisted?
rescue HTTP::Error, OpenSSL::SSL::SSLError, Addressable::URI::InvalidURIError, Mastodon::HostValidationError, Mastodon::LengthValidationError, EncodingError, ActiveRecord::RecordInvalid => e
rescue HTTP::Error, OpenSSL::SSL::SSLError, Addressable::URI::InvalidURIError, Mastodon::HostValidationError, Mastodon::LengthValidationError, Encoding::UndefinedConversionError, ActiveRecord::RecordInvalid => e
Rails.logger.debug { "Error fetching link #{@original_url}: #{e}" }
nil
end
@ -80,7 +80,7 @@ class FetchLinkCardService < BaseService
urls = if @status.local?
@status.text.scan(URL_PATTERN).map { |array| Addressable::URI.parse(array[1]).normalize }
else
document = Nokogiri::HTML(@status.text)
document = Nokogiri::HTML5(@status.text)
links = document.css('a')
links.filter_map { |a| Addressable::URI.parse(a['href']) unless skip_link?(a) }.filter_map(&:normalize)