detector.strip_tags = true
guess = detector.detect(@html, @html_charset)
- page = Nokogiri::HTML(@html, nil, guess&.fetch(:encoding, nil))
+ encoding = guess&.fetch(:confidence, 0).to_i > 60 ? guess&.fetch(:encoding, nil) : nil
+ page = Nokogiri::HTML(@html, nil, encoding)
player_url = meta_property(page, 'twitter:player')
if player_url && !bad_url?(Addressable::URI.parse(player_url))
--- /dev/null
+HTTP/1.1 200 OK\r
+server: nginx\r
+date: Wed, 12 Dec 2018 13:14:03 GMT\r
+content-type: text/html\r
+content-length: 190\r
+accept-ranges: bytes\r
+\r
+<!DOCTYPE html>\r
+<html>\r
+<head>\r
+ <meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />\r
+ <title>����� �����</title>\r
+</head>\r
+<body>\r
+ <p>����� �����</p>\r
+</body>\r
+</html>\r
stub_request(:head, 'https://github.com/qbi/WannaCry').to_return(status: 404)
stub_request(:head, 'http://example.com/test-').to_return(status: 200, headers: { 'Content-Type' => 'text/html' })
stub_request(:get, 'http://example.com/test-').to_return(request_fixture('idn.txt'))
+ stub_request(:head, 'http://example.com/windows-1251').to_return(status: 200, headers: { 'Content-Type' => 'text/html' })
+ stub_request(:get, 'http://example.com/windows-1251').to_return(request_fixture('windows-1251.txt'))
subject.call(status)
end
end
end
+ context do
+ let(:status) { Fabricate(:status, text: 'Check out http://example.com/windows-1251') }
+
+ it 'works with windows-1251' do
+ expect(a_request(:get, 'http://example.com/windows-1251')).to have_been_made.at_least_once
+ expect(status.preview_cards.first.title).to eq('сэмпл текст')
+ end
+ end
+
context do
let(:status) { Fabricate(:status, text: 'テストhttp://example.com/日本語') }