mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
FIX: don't extract link with 'mailto' scheme
This commit is contained in:
parent
b00ea5dc92
commit
f382897952
2 changed files with 16 additions and 7 deletions
|
@ -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'
|
||||||
|
|
|
@ -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")
|
||||||
|
|
Loading…
Reference in a new issue