fixes #1195; fix metatag case sensitivity

This commit is contained in:
Toks
2013-04-21 11:44:38 -04:00
parent 5e8bb942f7
commit 53c8babe3e

View File

@@ -380,17 +380,18 @@ class Post < ActiveRecord::Base
def normalize_tags def normalize_tags
normalized_tags = Tag.scan_tags(tag_string) normalized_tags = Tag.scan_tags(tag_string)
normalized_tags = filter_metatags(normalized_tags)
normalized_tags = normalized_tags.map{|tag| tag.downcase}
normalized_tags = TagAlias.to_aliased(normalized_tags) normalized_tags = TagAlias.to_aliased(normalized_tags)
normalized_tags = TagImplication.with_descendants(normalized_tags) normalized_tags = TagImplication.with_descendants(normalized_tags)
normalized_tags = filter_metatags(normalized_tags)
normalized_tags = %w(tagme) if normalized_tags.empty? normalized_tags = %w(tagme) if normalized_tags.empty?
normalized_tags.sort! normalized_tags.sort!
set_tag_string(normalized_tags.uniq.sort.join(" ")) set_tag_string(normalized_tags.uniq.sort.join(" "))
end end
def filter_metatags(tags) def filter_metatags(tags)
@pre_metatags, tags = tags.partition {|x| x =~ /\A(?:rating|parent):/} @pre_metatags, tags = tags.partition {|x| x =~ /\A(?:rating|parent):/i}
@post_metatags, tags = tags.partition {|x| x =~ /\A(?:-pool|pool|fav):/} @post_metatags, tags = tags.partition {|x| x =~ /\A(?:-pool|pool|fav):/i}
apply_pre_metatags apply_pre_metatags
return tags return tags
end end
@@ -400,26 +401,26 @@ class Post < ActiveRecord::Base
@post_metatags.each do |tag| @post_metatags.each do |tag|
case tag case tag
when /^-pool:(\d+)$/ when /^-pool:(\d+)$/i
pool = Pool.find_by_id($1.to_i) pool = Pool.find_by_id($1.to_i)
remove_pool!(pool) if pool remove_pool!(pool) if pool
when /^-pool:(.+)$/ when /^-pool:(.+)$/i
pool = Pool.find_by_name($1) pool = Pool.find_by_name($1)
remove_pool!(pool) if pool remove_pool!(pool) if pool
when /^pool:(\d+)$/ when /^pool:(\d+)$/i
pool = Pool.find_by_id($1.to_i) pool = Pool.find_by_id($1.to_i)
add_pool!(pool) if pool add_pool!(pool) if pool
when /^pool:(.+)$/ when /^pool:(.+)$/i
pool = Pool.find_by_name($1) pool = Pool.find_by_name($1)
if pool.nil? if pool.nil?
pool = Pool.create(:name => $1, :description => "This pool was automatically generated") pool = Pool.create(:name => $1, :description => "This pool was automatically generated")
end end
add_pool!(pool) if pool add_pool!(pool) if pool
when /^fav:(.+)$/ when /^fav:(.+)$/i
add_favorite!(CurrentUser.user) add_favorite!(CurrentUser.user)
end end
end end
@@ -430,10 +431,10 @@ class Post < ActiveRecord::Base
@pre_metatags.each do |tag| @pre_metatags.each do |tag|
case tag case tag
when /^parent:none$/, /^parent:0$/ when /^parent:none$/i, /^parent:0$/i
self.parent_id = nil self.parent_id = nil
when /^parent:(\d+)$/ when /^parent:(\d+)$/i
if Post.exists?(["id = ? and is_deleted = false", $1.to_i]) if Post.exists?(["id = ? and is_deleted = false", $1.to_i])
self.parent_id = $1.to_i self.parent_id = $1.to_i
end end