commit: 08e94d1b197a053504ce37dbbe03216a80043b10
parent: 2fba94b36eac65a368ec10f4c8c5808baa0179e7
Author: abcang <abcang1015@gmail.com>
Date: Wed, 10 May 2017 01:17:41 +0900
Fixed bug that timeline can not be displayed by InvalidURIError (#2947)
Diffstat:
2 files changed, 9 insertions(+), 0 deletions(-)
diff --git 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
@@ -123,6 +123,13 @@ RSpec.describe Formatter do
expect(subject).to match '<p><img src="javascript:alert('XSS');"></p>'
end
end
+
+ context 'contains invalid URL' do
+ let(:local_text) { 'http://www\.google\.com' }
+ it 'has valid url' do
+ expect(subject).to eq '<p>http://www\.google\.com</p>'
+ end
+ end
end
describe '#reformat' do