From 5b538cde50e892d2d51a59ad640241717ee83957 Mon Sep 17 00:00:00 2001 From: abcang Date: Wed, 10 May 2017 01:17:41 +0900 Subject: [PATCH] Fixed bug that timeline can not be displayed by InvalidURIError (#2947) --- app/lib/formatter.rb | 2 ++ spec/lib/formatter_spec.rb | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/app/lib/formatter.rb b/app/lib/formatter.rb index 12b030e117..0f2989a81f 100644 --- a/app/lib/formatter.rb +++ b/app/lib/formatter.rb @@ -92,6 +92,8 @@ class Formatter rel: 'nofollow noopener', } Twitter::Autolink.send(:link_to_text, entity, link_html(entity[:url]), normalized_url, html_attrs) + rescue Addressable::URI::InvalidURIError + encode(entity[:url]) end def link_to_mention(entity, mentions) diff --git a/spec/lib/formatter_spec.rb b/spec/lib/formatter_spec.rb index 81eaf00e80..791bcce866 100644 --- a/spec/lib/formatter_spec.rb +++ b/spec/lib/formatter_spec.rb @@ -123,6 +123,13 @@ RSpec.describe Formatter do expect(subject).to match '

<img src="javascript:alert('XSS');">

' end end + + context 'contains invalid URL' do + let(:local_text) { 'http://www\.google\.com' } + it 'has valid url' do + expect(subject).to eq '

http://www\.google\.com

' + end + end end describe '#reformat' do