Merge tag 'v4.3.0-rc.1'
This commit is contained in:
commit
26c9b9ba39
3459 changed files with 130932 additions and 69993 deletions
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe FetchLinkCardService, type: :service do
|
||||
RSpec.describe FetchLinkCardService do
|
||||
subject { described_class.new }
|
||||
|
||||
let(:html) { '<!doctype html><title>Hello world</title>' }
|
||||
|
|
@ -27,6 +27,12 @@ RSpec.describe FetchLinkCardService, type: :service do
|
|||
stub_request(:get, 'http://example.com/koi8-r').to_return(request_fixture('koi8-r.txt'))
|
||||
stub_request(:get, 'http://example.com/windows-1251').to_return(request_fixture('windows-1251.txt'))
|
||||
stub_request(:get, 'http://example.com/low_confidence_latin1').to_return(request_fixture('low_confidence_latin1.txt'))
|
||||
stub_request(:get, 'http://example.com/latin1_posing_as_utf8_broken').to_return(request_fixture('latin1_posing_as_utf8_broken.txt'))
|
||||
stub_request(:get, 'http://example.com/latin1_posing_as_utf8_recoverable').to_return(request_fixture('latin1_posing_as_utf8_recoverable.txt'))
|
||||
stub_request(:get, 'http://example.com/aergerliche-umlaute').to_return(request_fixture('redirect_with_utf8_url.txt'))
|
||||
stub_request(:get, 'http://example.com/page_without_title').to_return(request_fixture('page_without_title.txt'))
|
||||
stub_request(:get, 'http://example.com/long_canonical_url').to_return(request_fixture('long_canonical_url.txt'))
|
||||
stub_request(:get, 'http://example.com/alternative_utf8_spelling_in_header').to_return(request_fixture('alternative_utf8_spelling_in_header.txt'))
|
||||
|
||||
Rails.cache.write('oembed_endpoint:example.com', oembed_cache) if oembed_cache
|
||||
|
||||
|
|
@ -101,6 +107,22 @@ RSpec.describe FetchLinkCardService, type: :service do
|
|||
end
|
||||
end
|
||||
|
||||
context 'with a redirect URL with faulty encoding' do
|
||||
let(:status) { Fabricate(:status, text: 'http://example.com/aergerliche-umlaute') }
|
||||
|
||||
it 'does not create a preview card' do
|
||||
expect(status.preview_card).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a page that has no title' do
|
||||
let(:status) { Fabricate(:status, text: 'http://example.com/page_without_title') }
|
||||
|
||||
it 'does not create a preview card' do
|
||||
expect(status.preview_card).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a 404 URL' do
|
||||
let(:status) { Fabricate(:status, text: 'http://example.com/not-found') }
|
||||
|
||||
|
|
@ -121,7 +143,7 @@ RSpec.describe FetchLinkCardService, type: :service do
|
|||
let(:status) { Fabricate(:status, text: 'Check out http://example.com/sjis') }
|
||||
|
||||
it 'decodes the HTML' do
|
||||
expect(status.preview_cards.first.title).to eq('SJISのページ')
|
||||
expect(status.preview_card.title).to eq('SJISのページ')
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -129,7 +151,7 @@ RSpec.describe FetchLinkCardService, type: :service do
|
|||
let(:status) { Fabricate(:status, text: 'Check out http://example.com/sjis_with_wrong_charset') }
|
||||
|
||||
it 'decodes the HTML despite the wrong charset header' do
|
||||
expect(status.preview_cards.first.title).to eq('SJISのページ')
|
||||
expect(status.preview_card.title).to eq('SJISのページ')
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -137,7 +159,7 @@ RSpec.describe FetchLinkCardService, type: :service do
|
|||
let(:status) { Fabricate(:status, text: 'Check out http://example.com/koi8-r') }
|
||||
|
||||
it 'decodes the HTML' do
|
||||
expect(status.preview_cards.first.title).to eq('Московя начинаетъ только въ XVI ст. привлекать внимане иностранцевъ.')
|
||||
expect(status.preview_card.title).to eq('Московя начинаетъ только въ XVI ст. привлекать внимане иностранцевъ.')
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -145,15 +167,35 @@ RSpec.describe FetchLinkCardService, type: :service do
|
|||
let(:status) { Fabricate(:status, text: 'Check out http://example.com/windows-1251') }
|
||||
|
||||
it 'decodes the HTML' do
|
||||
expect(status.preview_cards.first.title).to eq('сэмпл текст')
|
||||
expect(status.preview_card.title).to eq('сэмпл текст')
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a URL of a page in ISO-8859-1 encoding, that charlock_holmes cannot detect' do
|
||||
let(:status) { Fabricate(:status, text: 'Check out http://example.com/low_confidence_latin1') }
|
||||
context 'when encoding in http header is correct' do
|
||||
let(:status) { Fabricate(:status, text: 'Check out http://example.com/low_confidence_latin1') }
|
||||
|
||||
it 'decodes the HTML' do
|
||||
expect(status.preview_card.title).to eq("Tofu á l'orange")
|
||||
it 'decodes the HTML' do
|
||||
expect(status.preview_card.title).to eq("Tofu á l'orange")
|
||||
end
|
||||
end
|
||||
|
||||
context 'when encoding in http header is incorrect' do
|
||||
context 'when encoding problems appear in unrelated tags' do
|
||||
let(:status) { Fabricate(:status, text: 'Check out http://example.com/latin1_posing_as_utf8_recoverable') }
|
||||
|
||||
it 'decodes the HTML' do
|
||||
expect(status.preview_card.title).to eq('Tofu with orange sauce')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when encoding problems appear in title tag' do
|
||||
let(:status) { Fabricate(:status, text: 'Check out http://example.com/latin1_posing_as_utf8_broken') }
|
||||
|
||||
it 'creates a preview card anyway that replaces invalid bytes with U+FFFD (replacement char)' do
|
||||
expect(status.preview_card.title).to eq("Tofu <20> l'orange")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -256,6 +298,22 @@ RSpec.describe FetchLinkCardService, type: :service do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a URL of a page that includes a canonical URL too long for PostgreSQL unique indexes' do
|
||||
let(:status) { Fabricate(:status, text: 'test http://example.com/long_canonical_url') }
|
||||
|
||||
it 'does not create a preview card' do
|
||||
expect(status.preview_card).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a URL where the `Content-Type` header uses `utf8` instead of `utf-8`' do
|
||||
let(:status) { Fabricate(:status, text: 'test http://example.com/alternative_utf8_spelling_in_header') }
|
||||
|
||||
it 'does not create a preview card' do
|
||||
expect(status.preview_card.title).to eq 'Webserver Configs R Us'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a remote status' do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue