mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 20:11:11 +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
|
||||
|
||||
def create
|
||||
|
||||
@manager_params = create_params
|
||||
@manager_params[:first_post_checks] = !is_api?
|
||||
|
||||
|
@ -1267,7 +1267,14 @@ SQL
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
private
|
||||
|
@ -2099,12 +2099,14 @@ describe Topic do
|
||||
describe '#featured_link_root_domain' do
|
||||
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/?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|
|
||||
it "should extract the root domain from #{featured_link} correctly" do
|
||||
topic.featured_link = featured_link
|
||||
expect(topic.featured_link_root_domain).to eq("discourse.org")
|
||||
end
|
||||
|
Reference in New Issue
Block a user