Fix #2894: Use [[:space:]] instead of \s in regexes.

This commit is contained in:
evazion
2018-09-20 19:13:31 -05:00
parent 29cdaddd86
commit 03abbd0683
24 changed files with 56 additions and 44 deletions

View File

@@ -24,11 +24,9 @@ class AliasAndImplicationImporter
end
def self.tokenize(text)
text = text.dup
text.gsub!(/^\s+/, "")
text.gsub!(/\s+$/, "")
text.gsub!(/ {2,}/, " ")
text.split(/\r\n|\r|\n/).map do |line|
line = line.gsub(/[[:space:]]+/, " ").strip
if line =~ /^(?:create alias|aliasing|alias) (\S+) -> (\S+)$/i
[:create_alias, $1, $2]

View File

@@ -33,13 +33,13 @@ module GoogleBigQuery
constraints << "updater_id = #{user_id.to_i}"
if added_tags
added_tags.scan(/\S+/).each do |tag|
added_tags.split.each do |tag|
constraints << add_tag_condition(tag)
end
end
if removed_tags
removed_tags.scan(/\S+/).each do |tag|
removed_tags.split.each do |tag|
constraints << remove_tag_condition(tag)
end
end

View File

@@ -22,7 +22,7 @@ module PostSets
end
def unordered_tag_array
tag_array.reject{|tag| tag =~ /\Aorder:\S+/}
tag_array.reject {|tag| tag =~ /\Aorder:/i }
end
def has_wiki?
@@ -55,7 +55,7 @@ module PostSets
end
def pool_name
tag_string.match(/^(?:ord)?pool:(\S+)$/i).try(:[], 1)
@pool_name ||= Tag.has_metatag?(tag_array, :ordpool, :pool)
end
def has_pool?
@@ -67,7 +67,7 @@ module PostSets
end
def favgroup_name
tag_string.match(/^favgroup:(\S+)$/i).try(:[], 1)
@favgroup_name ||= Tag.has_metatag?(tag_array, :favgroup)
end
def has_favgroup?

View File

@@ -27,7 +27,7 @@ class RelatedTagCalculator
CurrentUser.without_safe_mode do
Post.with_timeout(5_000, [], {:tags => tag}) do
Post.tag_match(tag).limit(400).reorder("posts.md5").pluck(:tag_string).each do |tag_string|
tag_string.scan(/\S+/).each do |tag|
tag_string.split.each do |tag|
counts[tag] += 1
end
end

View File

@@ -96,7 +96,7 @@ private
if (cookies[:favorite_tags].blank? || cookies[:favorite_tags_with_categories].blank?) && CurrentUser.user.favorite_tags.present?
favorite_tags = CurrentUser.user.favorite_tags.slice(0, 1024)
cookies[:favorite_tags] = favorite_tags
cookies[:favorite_tags_with_categories] = Tag.categories_for(favorite_tags.scan(/\S+/)).to_a.flatten.join(" ")
cookies[:favorite_tags_with_categories] = Tag.categories_for(favorite_tags.split(/[[:space:]]+/)).to_a.flatten.join(" ")
end
end

View File

@@ -233,7 +233,7 @@ class Artist < ApplicationRecord
end
def other_names_array
other_names.try(:split, /\s/)
other_names.try(:split, /[[:space:]]+/)
end
def other_names_comma

View File

@@ -48,11 +48,11 @@ class ArtistVersion < ApplicationRecord
extend SearchMethods
def url_array
url_string.to_s.scan(/\S+/)
url_string.to_s.split(/[[:space:]]+/)
end
def other_names_array
other_names.to_s.scan(/\S+/)
other_names.to_s.split(/[[:space:]]+/)
end
def urls_diff(version)

View File

@@ -3,7 +3,7 @@ class Comment < ApplicationRecord
validate :validate_post_exists, :on => :create
validate :validate_creator_is_not_limited, :on => :create
validates_format_of :body, :with => /\S/, :message => 'has no content'
validates_presence_of :body, :message => "has no content"
belongs_to :post
belongs_to_creator
belongs_to_updater

View File

@@ -8,13 +8,8 @@ class Dmail < ApplicationRecord
include Rakismet::Model
with_options on: :create do
validates_presence_of :to_id
validates_presence_of :from_id
validates_format_of :title, :with => /\S/
validates_format_of :body, :with => /\S/
validate :validate_sender_is_not_banned
end
validates_presence_of :title, :body, on: :create
validate :validate_sender_is_not_banned, on: :create
belongs_to :owner, :class_name => "User"
belongs_to :to, :class_name => "User"
@@ -217,7 +212,7 @@ class Dmail < ApplicationRecord
extend SearchMethods
def validate_sender_is_not_banned
if from.is_banned?
if from.try(:is_banned?)
errors[:base] << "Sender is banned and cannot send messages"
return false
else

View File

@@ -18,6 +18,6 @@ class DmailFilter < ApplicationRecord
end
def regexp
@regexp ||= Regexp.compile('\b(?:' + words.scan(/\S+/).map {|x| Regexp.escape(x)}.join("|") + ')\b')
@regexp ||= /\b#{Regexp.union(words.split(/[[:space:]]+/))}\b/
end
end

View File

@@ -108,7 +108,7 @@ class FavoriteGroup < ApplicationRecord
end
def self.normalize_name(name)
name.gsub(/\s+/, "_")
name.gsub(/[[:space:]]+/, "_")
end
def normalize_name

View File

@@ -970,7 +970,7 @@ class Post < ApplicationRecord
end
def clean_fav_string!
array = fav_string.scan(/\S+/).uniq
array = fav_string.split.uniq
self.fav_string = array.join(" ")
self.fav_count = array.size
update_column(:fav_string, fav_string)
@@ -1113,7 +1113,7 @@ class Post < ApplicationRecord
end
def set_pool_category_pseudo_tags
self.pool_string = (pool_string.scan(/\S+/) - ["pool:series", "pool:collection"]).join(" ")
self.pool_string = (pool_string.split - ["pool:series", "pool:collection"]).join(" ")
pool_categories = pools.undeleted.pluck(:category)
if pool_categories.include?("series")
@@ -1157,7 +1157,7 @@ class Post < ApplicationRecord
def fast_count(tags = "", options = {})
tags = tags.to_s
tags += " rating:s" if CurrentUser.safe_mode?
tags += " -status:deleted" if CurrentUser.hide_deleted_posts? && tags !~ /(?:^|\s)(?:-)?status:.+/
tags += " -status:deleted" if CurrentUser.hide_deleted_posts? && !Tag.has_metatag?(tags, "status", "-status")
tags = Tag.normalize_query(tags)
# optimize some cases. these are just estimates but at these

View File

@@ -88,7 +88,7 @@ class PostArchive < ApplicationRecord
include ArchiveServiceMethods
def tag_array
tags.scan(/\S+/)
tags.split
end
def presenter

View File

@@ -51,7 +51,7 @@ class PostVersion < ApplicationRecord
end
def tag_array
@tag_array ||= tags.scan(/\S+/)
@tag_array ||= tags.split
end
def reload

View File

@@ -179,7 +179,7 @@ class Tag < ApplicationRecord
while counts.empty? && n < 1000
tag_strings = Post.select_values_sql("select tag_string from posts where created_at >= ?", n.hours.ago)
tag_strings.each do |tag_string|
tag_string.scan(/\S+/).each do |tag|
tag_string.split.each do |tag|
counts[tag] ||= 0
counts[tag] += 1
end

View File

@@ -239,8 +239,8 @@ class Upload < ApplicationRecord
end
def assign_rating_from_tags
if tag_string =~ /(?:\s|^)rating:([qse])/i
self.rating = $1.downcase
if rating = Tag.has_metatag?(tag_string, :rating)
self.rating = rating.downcase
end
end

View File

@@ -234,6 +234,6 @@ class WikiPage < ApplicationRecord
end
def other_names_array
other_names.to_s.scan(/\S+/)
other_names.to_s.split(/[[:space:]]+/)
end
end

View File

@@ -47,6 +47,6 @@ class WikiPageVersion < ApplicationRecord
end
def other_names_array
other_names.to_s.scan(/\S+/)
other_names.to_s.split(/[[:space:]]+/)
end
end

View File

@@ -199,7 +199,7 @@ class PostPresenter < Presenter
end
def has_sequential_navigation?(params)
return false if params[:tags] =~ /(?:^|\s)(?:order|ordfav|ordpool):/i
return false if Tag.has_metatag?(params[:tags], :order, :ordfav, :ordpool)
return false if params[:pool_id].present? || params[:favgroup_id].present?
return CurrentUser.user.enable_sequential_post_navigation
end

View File

@@ -180,4 +180,14 @@ class UserPresenter
def previous_names(template)
user.user_name_change_requests.map { |req| template.link_to req.original_name, req }.join(", ").html_safe
end
def custom_css
user.custom_style.to_s.split(/\r\n|\r|\n/).map do |line|
if line =~ /\A@import/
line
else
line.gsub(/([^[:space:]])[[:space:]]*(?:!important)?[[:space:]]*(;|})/, "\\1 !important\\2")
end
end.join("\n")
end
end

View File

@@ -1,7 +1 @@
<% CurrentUser.user.custom_style.to_s.split(/\r\n|\r|\n/).each do |line| %>
<% if line =~ /^@import/ %>
<%= raw(line) %>
<% else %>
<%= raw(line.gsub(/(\S)\s*(?:!important)?\s*(;|})/, "\\1 !important\\2")) %>
<% end %>
<% end %>
<%= raw CurrentUser.user.presenter.custom_css %>