mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 03:36:18 +08:00
FIX: Topic#featured_link_root_domain
extracts URL before parsing.
This commit is contained in:
@ -133,7 +133,6 @@ class PostsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
|
||||||
@manager_params = create_params
|
@manager_params = create_params
|
||||||
@manager_params[:first_post_checks] = !is_api?
|
@manager_params[:first_post_checks] = !is_api?
|
||||||
|
|
||||||
|
@ -1267,7 +1267,14 @@ SQL
|
|||||||
end
|
end
|
||||||
|
|
||||||
def featured_link_root_domain
|
def featured_link_root_domain
|
||||||
MiniSuffix.domain(URI.parse(self.featured_link).hostname)
|
url = URI.extract(self.featured_link).first
|
||||||
|
|
||||||
|
begin
|
||||||
|
MiniSuffix.domain(URI.parse(url).hostname)
|
||||||
|
rescue URI::InvalidURIError => e
|
||||||
|
Rails.logger.warn("#{e.message}: #{e.backtrace.join("\n")}")
|
||||||
|
nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -2099,12 +2099,14 @@ describe Topic do
|
|||||||
describe '#featured_link_root_domain' do
|
describe '#featured_link_root_domain' do
|
||||||
let(:topic) { Fabricate.build(:topic) }
|
let(:topic) { Fabricate.build(:topic) }
|
||||||
|
|
||||||
it 'should extract the root domain correctly' do
|
|
||||||
[
|
[
|
||||||
"https://meta.discourse.org",
|
"https://meta.discourse.org",
|
||||||
"https://meta.discourse.org/",
|
"https://meta.discourse.org/",
|
||||||
"https://meta.discourse.org/?filter=test"
|
"https://meta.discourse.org/?filter=test",
|
||||||
|
"https://meta.discourse.org/ there might be text",
|
||||||
|
"http://meta.discourse.org/\u0441",
|
||||||
].each do |featured_link|
|
].each do |featured_link|
|
||||||
|
it "should extract the root domain from #{featured_link} correctly" do
|
||||||
topic.featured_link = featured_link
|
topic.featured_link = featured_link
|
||||||
expect(topic.featured_link_root_domain).to eq("discourse.org")
|
expect(topic.featured_link_root_domain).to eq("discourse.org")
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user