From 311f457430e4863f3c74fe6e222a96f62fc0148d Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Tue, 13 Oct 2020 12:47:38 +0200 Subject: Fix crash when autolinking an invalid URI in Markdown --- spec/lib/formatter_spec.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/formatter_spec.rb b/spec/lib/formatter_spec.rb index 633d59c2a..efefb8f00 100644 --- a/spec/lib/formatter_spec.rb +++ b/spec/lib/formatter_spec.rb @@ -336,11 +336,22 @@ RSpec.describe Formatter do end context do + let(:content_type) { 'text/plain' } + subject do - status = Fabricate(:status, text: text, uri: nil) + status = Fabricate(:status, text: text, content_type: content_type, uri: nil) Formatter.instance.format(status) end + context 'given an invalid URL (invalid port)' do + let(:text) { 'https://foo.bar:X/' } + let(:content_type) { 'text/markdown' } + + it 'outputs the raw URL' do + is_expected.to eq '

https://foo.bar:X/

' + end + end + include_examples 'encode and link URLs' end @@ -464,7 +475,8 @@ RSpec.describe Formatter do subject { Formatter.instance.plaintext(status) } context 'given a post with local status' do - let(:status) { Fabricate(:status, text: '

a text by a nerd who uses an HTML tag in text

', uri: nil) } + let(:status) { Fabricate(:status, text: '

a text by a nerd who uses an HTML tag in text

', content_type: content_type, uri: nil) } + let(:content_type) { 'text/plain' } it 'returns the raw text' do is_expected.to eq '

a text by a nerd who uses an HTML tag in text

' -- cgit