mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 07:53:49 +08:00
DEV: Merge category and tag hashtags code paths (#10216)
Category and tag hashtags used to be handled differently even though most of the code was very similar. This design was the root cause of multiple issues related to hashtags. This commit reduces the number of requests (just one and debounced better), removes the use of CSS classes which marked resolved hashtags, simplifies a lot of the code as there is a single source of truth and previous race condition fixes are now useless. It also includes a very minor security fix which let unauthorized users to guess hidden tags.
This commit is contained in:
@ -4,6 +4,8 @@ module PrettyText
|
||||
module Helpers
|
||||
extend self
|
||||
|
||||
TAG_HASHTAG_POSTFIX = "::tag"
|
||||
|
||||
# functions here are available to v8
|
||||
def t(key, opts)
|
||||
key = "js." + key
|
||||
@ -102,13 +104,12 @@ module PrettyText
|
||||
end
|
||||
|
||||
def category_tag_hashtag_lookup(text)
|
||||
tag_postfix = '::tag'
|
||||
is_tag = text =~ /#{tag_postfix}$/
|
||||
is_tag = text =~ /#{TAG_HASHTAG_POSTFIX}$/
|
||||
|
||||
if !is_tag && category = Category.query_from_hashtag_slug(text)
|
||||
[category.url, text]
|
||||
elsif (!is_tag && tag = Tag.find_by(name: text)) ||
|
||||
(is_tag && tag = Tag.find_by(name: text.gsub!("#{tag_postfix}", '')))
|
||||
(is_tag && tag = Tag.find_by(name: text.gsub!(TAG_HASHTAG_POSTFIX, '')))
|
||||
["#{Discourse.base_url}/tag/#{tag.name}", text]
|
||||
else
|
||||
nil
|
||||
|
Reference in New Issue
Block a user