diff --git a/lib/gitlab/markdown/autolink_filter.rb b/lib/gitlab/markdown/autolink_filter.rb index 9889d6643ab4bb895023c8d3cedc8aca734f839c..f0b68bab8254a6d5455407a484d38d8e5b056e03 100644 --- a/lib/gitlab/markdown/autolink_filter.rb +++ b/lib/gitlab/markdown/autolink_filter.rb @@ -52,7 +52,10 @@ module Gitlab # NOTE: We don't parse email links because it will erroneously match # external Commit and CommitRange references. - rinku = Rinku.auto_link(html, :urls, options, IGNORE_PARENTS.to_a) + # + # The final argument tells Rinku to link short URLs that don't include a + # period (e.g., http://localhost:3000/) + rinku = Rinku.auto_link(html, :urls, options, IGNORE_PARENTS.to_a, 1) # Rinku returns a String, so parse it back to a Nokogiri::XML::Document # for further processing. diff --git a/spec/features/markdown_spec.rb b/spec/features/markdown_spec.rb index 9db1a0a241878971026edeaac3ee568782ae3aee..3528200e12bdf445e7d1c01ee6eb473f954847d3 100644 --- a/spec/features/markdown_spec.rb +++ b/spec/features/markdown_spec.rb @@ -207,11 +207,9 @@ describe 'GitLab Markdown' do expect(item(5).children.first['href']).to eq 'irc://irc.freenode.net/git' end - # TODO (rspeicher): Do we really want this? it 'autolinks short, invalid URLs' do - skip 'rspeicher: Pending decision' expect(item(6).children.first.name).to eq 'a' - expect(item(6).children.first['href']).to eq 'http://foo' + expect(item(6).children.first['href']).to eq 'http://localhost:3000' end %w(code a kbd).each do |elem| diff --git a/spec/lib/gitlab/markdown/autolink_filter_spec.rb b/spec/lib/gitlab/markdown/autolink_filter_spec.rb index 83fee123330dd416cfd05c82d5ae36360b9c4311..0bbdc11a9798f6b82c3a7f8632ac63e4f6fe09f8 100644 --- a/spec/lib/gitlab/markdown/autolink_filter_spec.rb +++ b/spec/lib/gitlab/markdown/autolink_filter_spec.rb @@ -41,6 +41,14 @@ module Gitlab::Markdown expect(doc.at_css('a')['href']).to eq link end + it 'autolinks short URLs' do + link = 'http://localhost:3000/' + doc = filter("See #{link}") + + expect(doc.at_css('a').text).to eq link + expect(doc.at_css('a')['href']).to eq link + end + it 'accepts link_attr options' do doc = filter("See #{link}", link_attr: {class: 'custom'})