From ab763c493fd8d40db6005282c38bd2636120f273 Mon Sep 17 00:00:00 2001 From: David Roetzel Date: Thu, 12 Sep 2024 13:14:42 +0200 Subject: [PATCH] Ignore `undefined` as canonical url (#31882) --- app/lib/link_details_extractor.rb | 2 +- spec/lib/link_details_extractor_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/lib/link_details_extractor.rb b/app/lib/link_details_extractor.rb index dff57f74f3..e4e815c38d 100644 --- a/app/lib/link_details_extractor.rb +++ b/app/lib/link_details_extractor.rb @@ -225,7 +225,7 @@ class LinkDetailsExtractor end def valid_url_or_nil(str, same_origin_only: false) - return if str.blank? || str == 'null' + return if str.blank? || str == 'null' || str == 'undefined' url = @original_url + Addressable::URI.parse(str) diff --git a/spec/lib/link_details_extractor_spec.rb b/spec/lib/link_details_extractor_spec.rb index b1e5cedced..d8d9db0ad1 100644 --- a/spec/lib/link_details_extractor_spec.rb +++ b/spec/lib/link_details_extractor_spec.rb @@ -33,6 +33,14 @@ RSpec.describe LinkDetailsExtractor do expect(subject.canonical_url).to eq original_url end end + + context 'when canonical URL is set to "undefined"' do + let(:url) { 'undefined' } + + it 'ignores the canonical URLs' do + expect(subject.canonical_url).to eq original_url + end + end end context 'when only basic metadata is present' do