FIX: Allow really long links to work
This commit is contained in:
parent
2e76c9165a
commit
43c7320f55
|
@ -2,8 +2,14 @@ require 'uri'
|
||||||
require_dependency 'slug'
|
require_dependency 'slug'
|
||||||
|
|
||||||
class TopicLink < ActiveRecord::Base
|
class TopicLink < ActiveRecord::Base
|
||||||
MAX_DOMAIN_LENGTH = 100 unless defined? MAX_DOMAIN_LENGTH
|
|
||||||
MAX_URL_LENGTH = 500 unless defined? MAX_URL_LENGTH
|
def self.max_domain_length
|
||||||
|
100
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.max_url_length
|
||||||
|
500
|
||||||
|
end
|
||||||
|
|
||||||
belongs_to :topic
|
belongs_to :topic
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
@ -147,8 +153,8 @@ class TopicLink < ActiveRecord::Base
|
||||||
reflected_post = Post.find_by(topic_id: topic_id, post_number: post_number.to_i)
|
reflected_post = Post.find_by(topic_id: topic_id, post_number: post_number.to_i)
|
||||||
end
|
end
|
||||||
|
|
||||||
next if url && url.length > MAX_URL_LENGTH
|
url = url[0...TopicLink.max_url_length]
|
||||||
next if parsed && parsed.host && parsed.host.length > MAX_DOMAIN_LENGTH
|
next if parsed && parsed.host && parsed.host.length > TopicLink.max_domain_length
|
||||||
|
|
||||||
added_urls << url
|
added_urls << url
|
||||||
TopicLink.create(post_id: post.id,
|
TopicLink.create(post_id: post.id,
|
||||||
|
|
|
@ -13,7 +13,7 @@ class TopicLinkClick < ActiveRecord::Base
|
||||||
|
|
||||||
# Create a click from a URL and post_id
|
# Create a click from a URL and post_id
|
||||||
def self.create_from(args={})
|
def self.create_from(args={})
|
||||||
url = args[:url]
|
url = args[:url][0...TopicLink.max_url_length]
|
||||||
return nil if url.blank?
|
return nil if url.blank?
|
||||||
|
|
||||||
uri = URI.parse(url) rescue nil
|
uri = URI.parse(url) rescue nil
|
||||||
|
|
|
@ -37,7 +37,7 @@ http://b.com/#{'a'*500}
|
||||||
|
|
||||||
it 'works' do
|
it 'works' do
|
||||||
# has the forum topic links
|
# has the forum topic links
|
||||||
expect(topic.topic_links.count).to eq(2)
|
expect(topic.topic_links.count).to eq(3)
|
||||||
|
|
||||||
# works with markdown links
|
# works with markdown links
|
||||||
expect(topic.topic_links.exists?(url: "http://a.com/")).to eq(true)
|
expect(topic.topic_links.exists?(url: "http://a.com/")).to eq(true)
|
||||||
|
|
Loading…
Reference in New Issue