mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Prefer \A and \z over ^ and $ in regexes (#19936)
This commit is contained in:
committed by
GitHub
parent
f7907a3645
commit
666536cbd1
@@ -25,7 +25,7 @@ class TopicEmbed < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def self.normalize_url(url)
|
||||
url.downcase.sub(%r{/$}, "").sub(/\-+/, "-").strip
|
||||
url.downcase.sub(%r{/\z}, "").sub(/\-+/, "-").strip
|
||||
end
|
||||
|
||||
def self.imported_from_html(url)
|
||||
@@ -36,7 +36,7 @@ class TopicEmbed < ActiveRecord::Base
|
||||
|
||||
# Import an article from a source (RSS/Atom/Other)
|
||||
def self.import(user, url, title, contents, category_id: nil, cook_method: nil, tags: nil)
|
||||
return unless url =~ %r{^https?\://}
|
||||
return unless url =~ %r{\Ahttps?\://}
|
||||
|
||||
contents = first_paragraph_from(contents) if SiteSetting.embed_truncate && cook_method.nil?
|
||||
contents ||= ""
|
||||
@@ -253,7 +253,7 @@ class TopicEmbed < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def self.topic_id_for_embed(embed_url)
|
||||
embed_url = normalize_url(embed_url).sub(%r{^https?\://}, "")
|
||||
embed_url = normalize_url(embed_url).sub(%r{\Ahttps?\://}, "")
|
||||
TopicEmbed.where("embed_url ~* ?", "^https?://#{Regexp.escape(embed_url)}$").pluck_first(
|
||||
:topic_id,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user