Autofix Rubocop Regex Style rules (#23690)

Co-authored-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
Nick Schonning
2023-06-06 08:50:51 -04:00
committed by GitHub
parent 9a653899e9
commit c66250abf1
22 changed files with 46 additions and 92 deletions

View File

@ -7,15 +7,15 @@ class LinkDetailsExtractor
# Some publications wrap their JSON-LD data in their <script> tags
# in commented-out CDATA blocks, they need to be removed before
# attempting to parse JSON
CDATA_JUNK_PATTERN = %r{^[\s]*(
(/\*[\s]*<!\[CDATA\[[\s]*\*/) # Block comment style opening
CDATA_JUNK_PATTERN = %r{^\s*(
(/\*\s*<!\[CDATA\[\s*\*/) # Block comment style opening
|
(//[\s]*<!\[CDATA\[) # Single-line comment style opening
(//\s*<!\[CDATA\[) # Single-line comment style opening
|
(/\*[\s]*\]\]>[\s]*\*/) # Block comment style closing
(/\*\s*\]\]>\s*\*/) # Block comment style closing
|
(//[\s]*\]\]>) # Single-line comment style closing
)[\s]*$}x
(//\s*\]\]>) # Single-line comment style closing
)\s*$}x
class StructuredData
SUPPORTED_TYPES = %w(
@ -204,7 +204,7 @@ class LinkDetailsExtractor
def host_to_url(str)
return if str.blank?
str.start_with?(/https?:\/\//) ? str : "http://#{str}"
str.start_with?(%r{https?://}) ? str : "http://#{str}"
end
def valid_url_or_nil(str, same_origin_only: false)

View File

@ -3,7 +3,7 @@
class PlainTextFormatter
include ActionView::Helpers::TextHelper
NEWLINE_TAGS_RE = /(<br \/>|<br>|<\/p>)+/
NEWLINE_TAGS_RE = %r{(<br />|<br>|</p>)+}
attr_reader :text, :local

View File

@ -7,18 +7,18 @@ class TagManager
include RoutingHelper
def web_domain?(domain)
domain.nil? || domain.gsub(/[\/]/, '').casecmp(Rails.configuration.x.web_domain).zero?
domain.nil? || domain.delete('/').casecmp(Rails.configuration.x.web_domain).zero?
end
def local_domain?(domain)
domain.nil? || domain.gsub(/[\/]/, '').casecmp(Rails.configuration.x.local_domain).zero?
domain.nil? || domain.delete('/').casecmp(Rails.configuration.x.local_domain).zero?
end
def normalize_domain(domain)
return if domain.nil?
uri = Addressable::URI.new
uri.host = domain.gsub(/[\/]/, '')
uri.host = domain.delete('/')
uri.normalized_host
end

View File

@ -5,7 +5,7 @@ class TextFormatter
include ERB::Util
include RoutingHelper
URL_PREFIX_REGEX = /\A(https?:\/\/(www\.)?|xmpp:)/
URL_PREFIX_REGEX = %r{\A(https?://(www\.)?|xmpp:)}
DEFAULT_REL = %w(nofollow noopener noreferrer).freeze

View File

@ -13,7 +13,7 @@ class WebfingerResource
case resource
when /\Ahttps?/i
username_from_url
when /\@/
when /@/
username_from_acct
else
raise InvalidRequest

View File

@ -62,9 +62,9 @@ class Account < ApplicationRecord
trust_level
)
USERNAME_RE = /[a-z0-9_]+([a-z0-9_\.-]+[a-z0-9_]+)?/i
MENTION_RE = /(?<=^|[^\/[:word:]])@((#{USERNAME_RE})(?:@[[:word:]\.\-]+[[:word:]]+)?)/i
URL_PREFIX_RE = /\Ahttp(s?):\/\/[^\/]+/
USERNAME_RE = /[a-z0-9_]+([a-z0-9_.-]+[a-z0-9_]+)?/i
MENTION_RE = %r{(?<=^|[^/[:word:]])@((#{USERNAME_RE})(?:@[[:word:].-]+[[:word:]]+)?)}i
URL_PREFIX_RE = %r{\Ahttp(s?)://[^/]+}
USERNAME_ONLY_RE = /\A#{USERNAME_RE}\z/i
include Attachmentable

View File

@ -35,7 +35,7 @@ class DomainAllow < ApplicationRecord
def rule_for(domain)
return if domain.blank?
uri = Addressable::URI.new.tap { |u| u.host = domain.gsub(/[\/]/, '') }
uri = Addressable::URI.new.tap { |u| u.host = domain.delete('/') }
find_by(domain: uri.normalized_host)
end

View File

@ -67,7 +67,7 @@ class DomainBlock < ApplicationRecord
def rule_for(domain)
return if domain.blank?
uri = Addressable::URI.new.tap { |u| u.host = domain.strip.gsub(/[\/]/, '') }
uri = Addressable::URI.new.tap { |u| u.host = domain.strip.delete('/') }
segments = uri.normalized_host.split('.')
variants = segments.map.with_index { |_, i| segments[i..-1].join('.') }

View File

@ -43,7 +43,7 @@ class SiteUpload < ApplicationRecord
has_attached_file :file, styles: ->(file) { STYLES[file.instance.var.to_sym] }, convert_options: { all: '-coalesce +profile "!icc,*" +set modify-date +set create-date' }, processors: [:lazy_thumbnail, :blurhash_transcoder, :type_corrector]
validates_attachment_content_type :file, content_type: /\Aimage\/.*\z/
validates_attachment_content_type :file, content_type: %r{\Aimage/.*\z}
validates :file, presence: true
validates :var, presence: true, uniqueness: true

View File

@ -34,7 +34,7 @@ class Tag < ApplicationRecord
HASHTAG_LAST_SEQUENCE = '([[:word:]_]*[[:alpha:]][[:word:]_]*)'
HASHTAG_NAME_PAT = "#{HASHTAG_FIRST_SEQUENCE}|#{HASHTAG_LAST_SEQUENCE}"
HASHTAG_RE = /(?:^|[^\/\)\w])#(#{HASHTAG_NAME_PAT})/i
HASHTAG_RE = %r{(?:^|[^/)\w])#(#{HASHTAG_NAME_PAT})}i
HASHTAG_NAME_RE = /\A(#{HASHTAG_NAME_PAT})\z/i
HASHTAG_INVALID_CHARS_RE = /[^[:alnum:]#{HASHTAG_SEPARATORS}]/

View File

@ -77,8 +77,8 @@ class BackupService < BaseService
path = m.file&.path
next unless path
path = path.gsub(/\A.*\/system\//, '')
path = path.gsub(/\A\/+/, '')
path = path.gsub(%r{\A.*/system/}, '')
path = path.gsub(%r{\A/+}, '')
download_to_zip(zipfile, m.file, path)
end

View File

@ -7,7 +7,7 @@ class FetchLinkCardService < BaseService
URL_PATTERN = %r{
(#{Twitter::TwitterText::Regex[:valid_url_preceding_chars]}) # $1 preceding chars
( # $2 URL
(https?:\/\/) # $3 Protocol (required)
(https?://) # $3 Protocol (required)
(#{Twitter::TwitterText::Regex[:valid_domain]}) # $4 Domain(s)
(?::(#{Twitter::TwitterText::Regex[:valid_port_number]}))? # $5 Port number (optional)
(/#{Twitter::TwitterText::Regex[:valid_url_path]}*)? # $6 URL Path and anchor

View File

@ -2,7 +2,7 @@
class FetchOEmbedService
ENDPOINT_CACHE_EXPIRES_IN = 24.hours.freeze
URL_REGEX = /(=(http[s]?(%3A|:)(\/\/|%2F%2F)))([^&]*)/i
URL_REGEX = %r{(=(https?(%3A|:)(//|%2F%2F)))([^&]*)}i
attr_reader :url, :options, :format, :endpoint_url

View File

@ -70,7 +70,7 @@ class SearchService < BaseService
end
def url_query?
@resolve && /\Ahttps?:\/\//.match?(@query)
@resolve && %r{\Ahttps?://}.match?(@query)
end
def url_resource_results