FIX: don't extract link with 'mailto' scheme

This commit is contained in:
Régis Hanol 2016-04-05 00:43:11 +02:00
parent b00ea5dc92
commit f382897952
2 changed files with 16 additions and 7 deletions

View file

@ -110,25 +110,25 @@ class TopicLink < ActiveRecord::Base
PrettyText PrettyText
.extract_links(post.cooked) .extract_links(post.cooked)
.map{|u| [u, URI.parse(u.url)] rescue nil} .map { |u| [u, URI.parse(u.url)] rescue nil }
.reject{|_, p| p.nil?} .reject { |_, p| p.nil? || "mailto".freeze == p.scheme }
.uniq{|_, p| p} .uniq { |_, p| p }
.each do |link, parsed| .each do |link, parsed|
begin begin
url = link.url url = link.url
internal = false internal = false
topic_id = nil topic_id = nil
post_number = nil post_number = nil
parsed_path = parsed.path || ""
if Discourse.store.has_been_uploaded?(url) if Discourse.store.has_been_uploaded?(url)
internal = Discourse.store.internal? internal = Discourse.store.internal?
elsif (parsed.host == Discourse.current_hostname && parsed.path.start_with?(Discourse.base_uri)) || !parsed.host elsif (parsed.host == Discourse.current_hostname && parsed_path.start_with?(Discourse.base_uri)) || !parsed.host
internal = true internal = true
parsed.path.slice!(Discourse.base_uri) parsed_path.slice!(Discourse.base_uri)
route = Rails.application.routes.recognize_path(parsed.path) route = Rails.application.routes.recognize_path(parsed_path)
# We aren't interested in tracking internal links to users # We aren't interested in tracking internal links to users
next if route[:controller] == 'users' next if route[:controller] == 'users'

View file

@ -164,6 +164,15 @@ http://b.com/#{'a'*500}
end end
end end
context "mail link" do
let(:post) { topic.posts.create(user: user, raw: "[email]bar@example.com[/email]") }
it 'does not extract a link' do
TopicLink.extract_from(post)
expect(topic.topic_links).to be_blank
end
end
context "quote links" do context "quote links" do
it "sets quote correctly" do it "sets quote correctly" do
linked_post = topic.posts.create(user: user, raw: "my test post") linked_post = topic.posts.create(user: user, raw: "my test post")