From eb51e43fb4386120f77f2ff99581f15018a81bd4 Mon Sep 17 00:00:00 2001 From: luigi <007.lva@gmail.com> Date: Fri, 22 Jan 2021 04:09:08 -0500 Subject: [PATCH 1/7] Optimize some regex matching (#15528) * Use Regex#match? * Replace =~ too * Avoid to call match? from Nil * Keep value of Regexp.last_match --- app/lib/extractor.rb | 8 ++++---- app/lib/feed_manager.rb | 6 +++--- app/lib/formatter.rb | 2 +- app/lib/request.rb | 2 +- app/lib/sanitize_config.rb | 6 +++--- app/models/concerns/omniauthable.rb | 2 +- app/services/account_search_service.rb | 2 +- app/services/search_service.rb | 2 +- app/validators/blacklisted_email_validator.rb | 2 +- app/validators/html_validator.rb | 2 +- config/initializers/open_uri_redirection.rb | 2 +- config/initializers/rack_attack.rb | 2 +- lib/mastodon/domains_cli.rb | 2 +- 13 files changed, 20 insertions(+), 20 deletions(-) diff --git a/app/lib/extractor.rb b/app/lib/extractor.rb index 479689d602..6076458ad6 100644 --- a/app/lib/extractor.rb +++ b/app/lib/extractor.rb @@ -7,14 +7,14 @@ module Extractor # :yields: username, list_slug, start, end def extract_mentions_or_lists_with_indices(text) - return [] unless text =~ Twitter::Regex[:at_signs] + return [] unless Twitter::Regex[:at_signs].match?(text) possible_entries = [] text.to_s.scan(Account::MENTION_RE) do |screen_name, _| match_data = $LAST_MATCH_INFO after = $' - unless after =~ Twitter::Regex[:end_mention_match] + unless Twitter::Regex[:end_mention_match].match?(after) start_position = match_data.char_begin(1) - 1 end_position = match_data.char_end(1) possible_entries << { @@ -33,7 +33,7 @@ module Extractor end def extract_hashtags_with_indices(text, **) - return [] unless text =~ /#/ + return [] unless /#/.match?(text) tags = [] text.scan(Tag::HASHTAG_RE) do |hash_text, _| @@ -41,7 +41,7 @@ module Extractor start_position = match_data.char_begin(1) - 1 end_position = match_data.char_end(1) after = $' - if after =~ %r{\A://} + if %r{\A://}.match?(after) hash_text.match(/(.+)(https?\Z)/) do |matched| hash_text = matched[1] end_position -= matched[2].char_length diff --git a/app/lib/feed_manager.rb b/app/lib/feed_manager.rb index f0ad3e21fe..165338437b 100644 --- a/app/lib/feed_manager.rb +++ b/app/lib/feed_manager.rb @@ -396,8 +396,8 @@ class FeedManager active_filters.map! do |filter| if filter.whole_word - sb = filter.phrase =~ /\A[[:word:]]/ ? '\b' : '' - eb = filter.phrase =~ /[[:word:]]\z/ ? '\b' : '' + sb = /\A[[:word:]]/.match?(filter.phrase) ? '\b' : '' + eb = /[[:word:]]\z/.match?(filter.phrase) ? '\b' : '' /(?mix:#{sb}#{Regexp.escape(filter.phrase)}#{eb})/ else @@ -417,7 +417,7 @@ class FeedManager status.media_attachments.map(&:description).join("\n\n"), ].compact.join("\n\n") - !combined_regex.match(combined_text).nil? + combined_regex.match?(combined_text) end # Adds a status to an account's feed, returning true if a status was diff --git a/app/lib/formatter.rb b/app/lib/formatter.rb index 7f217ae9f6..24a34a0594 100644 --- a/app/lib/formatter.rb +++ b/app/lib/formatter.rb @@ -222,7 +222,7 @@ class Formatter escaped = text.chars.map do |c| output = begin - if c.ord.to_s(16).length > 2 && UNICODE_ESCAPE_BLACKLIST_RE.match(c).nil? + if c.ord.to_s(16).length > 2 && !UNICODE_ESCAPE_BLACKLIST_RE.match?(c) CGI.escape(c) else c diff --git a/app/lib/request.rb b/app/lib/request.rb index 38048dad7b..125dee3ea7 100644 --- a/app/lib/request.rb +++ b/app/lib/request.rb @@ -145,7 +145,7 @@ class Request end def block_hidden_service? - !Rails.configuration.x.access_to_hidden_service && /\.(onion|i2p)$/.match(@url.host) + !Rails.configuration.x.access_to_hidden_service && /\.(onion|i2p)$/.match?(@url.host) end module ClientLimit diff --git a/app/lib/sanitize_config.rb b/app/lib/sanitize_config.rb index 8f700197b2..a2e1d9d01b 100644 --- a/app/lib/sanitize_config.rb +++ b/app/lib/sanitize_config.rb @@ -28,9 +28,9 @@ class Sanitize return unless class_list class_list.keep_if do |e| - next true if e =~ /^(h|p|u|dt|e)-/ # microformats classes - next true if e =~ /^(mention|hashtag)$/ # semantic classes - next true if e =~ /^(ellipsis|invisible)$/ # link formatting classes + next true if /^(h|p|u|dt|e)-/.match?(e) # microformats classes + next true if /^(mention|hashtag)$/.match?(e) # semantic classes + next true if /^(ellipsis|invisible)$/.match?(e) # link formatting classes end node['class'] = class_list.join(' ') diff --git a/app/models/concerns/omniauthable.rb b/app/models/concerns/omniauthable.rb index 4ea219537a..79d671d10a 100644 --- a/app/models/concerns/omniauthable.rb +++ b/app/models/concerns/omniauthable.rb @@ -57,7 +57,7 @@ module Omniauthable user = User.new(user_params_from_auth(email, auth)) - user.account.avatar_remote_url = auth.info.image if auth.info.image =~ /\A#{URI::DEFAULT_PARSER.make_regexp(%w(http https))}\z/ + user.account.avatar_remote_url = auth.info.image if /\A#{URI::DEFAULT_PARSER.make_regexp(%w(http https))}\z/.match?(auth.info.image) user.skip_confirmation! user.save! user diff --git a/app/services/account_search_service.rb b/app/services/account_search_service.rb index 43e5960405..6fe4b6593a 100644 --- a/app/services/account_search_service.rb +++ b/app/services/account_search_service.rb @@ -175,7 +175,7 @@ class AccountSearchService < BaseService end def username_complete? - query.include?('@') && "@#{query}" =~ /\A#{Account::MENTION_RE}\Z/ + query.include?('@') && "@#{query}".match?(/\A#{Account::MENTION_RE}\Z/) end def likely_acct? diff --git a/app/services/search_service.rb b/app/services/search_service.rb index 19500a8d46..1a76cbb388 100644 --- a/app/services/search_service.rb +++ b/app/services/search_service.rb @@ -72,7 +72,7 @@ class SearchService < BaseService end def url_query? - @resolve && @query =~ /\Ahttps?:\/\// + @resolve && /\Ahttps?:\/\//.match?(@query) end def url_resource_results diff --git a/app/validators/blacklisted_email_validator.rb b/app/validators/blacklisted_email_validator.rb index 16e3abf129..20a1587cc6 100644 --- a/app/validators/blacklisted_email_validator.rb +++ b/app/validators/blacklisted_email_validator.rb @@ -22,7 +22,7 @@ class BlacklistedEmailValidator < ActiveModel::Validator domains = Rails.configuration.x.email_domains_blacklist.gsub('.', '\.') regexp = Regexp.new("@(.+\\.)?(#{domains})", true) - @email =~ regexp + regexp.match?(@email) end def not_on_whitelist? diff --git a/app/validators/html_validator.rb b/app/validators/html_validator.rb index 1c9cd303cf..b85b9769fb 100644 --- a/app/validators/html_validator.rb +++ b/app/validators/html_validator.rb @@ -15,6 +15,6 @@ class HtmlValidator < ActiveModel::EachValidator def html_errors(str) fragment = Nokogiri::HTML.fragment(options[:wrap_with] ? "<#{options[:wrap_with]}>#{str}" : str) - fragment.errors.select { |error| ERROR_RE =~ error.message } + fragment.errors.select { |error| ERROR_RE.match?(error.message) } end end diff --git a/config/initializers/open_uri_redirection.rb b/config/initializers/open_uri_redirection.rb index e9de85bdc5..0e57c53c63 100644 --- a/config/initializers/open_uri_redirection.rb +++ b/config/initializers/open_uri_redirection.rb @@ -3,6 +3,6 @@ require 'open-uri' module OpenURI def self.redirectable?(uri1, uri2) # :nodoc: uri1.scheme.casecmp(uri2.scheme).zero? || - (/\A(?:http|https|ftp)\z/i =~ uri1.scheme && /\A(?:http|https|ftp)\z/i =~ uri2.scheme) + (/\A(?:http|https|ftp)\z/i.match?(uri1.scheme) && /\A(?:http|https|ftp)\z/i.match?(uri2.scheme)) end end diff --git a/config/initializers/rack_attack.rb b/config/initializers/rack_attack.rb index 6662ef40b0..c0db499072 100644 --- a/config/initializers/rack_attack.rb +++ b/config/initializers/rack_attack.rb @@ -78,7 +78,7 @@ class Rack::Attack API_DELETE_STATUS_REGEX = /\A\/api\/v1\/statuses\/[\d]+/.freeze throttle('throttle_api_delete', limit: 30, period: 30.minutes) do |req| - req.authenticated_user_id if (req.post? && req.path =~ API_DELETE_REBLOG_REGEX) || (req.delete? && req.path =~ API_DELETE_STATUS_REGEX) + req.authenticated_user_id if (req.post? && req.path.match?(API_DELETE_REBLOG_REGEX)) || (req.delete? && req.path.match?(API_DELETE_STATUS_REGEX)) end throttle('throttle_sign_up_attempts/ip', limit: 25, period: 5.minutes) do |req| diff --git a/lib/mastodon/domains_cli.rb b/lib/mastodon/domains_cli.rb index 3c2dfd4ec2..4ebd8a1e2c 100644 --- a/lib/mastodon/domains_cli.rb +++ b/lib/mastodon/domains_cli.rb @@ -93,7 +93,7 @@ module Mastodon work_unit = ->(domain) do next if stats.key?(domain) - next if options[:exclude_suspended] && domain.match(blocked_domains) + next if options[:exclude_suspended] && domain.match?(blocked_domains) stats[domain] = nil From 5fcac81302ad323a86ab43243c242c4a10cd338a Mon Sep 17 00:00:00 2001 From: ThibG Date: Fri, 22 Jan 2021 10:09:23 +0100 Subject: [PATCH 2/7] =?UTF-8?q?Add=20=E2=80=9Ctranslate=E2=80=9D=20class?= =?UTF-8?q?=20to=20other=20user=20strings=20(#15611)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add “translate” class to other user strings Follow-up to #15610. Allow Google Translate to work on more user content: - poll options - reply indicator (contents of the status being replied to) - directory account cards - account note in follow requests list * Fix incorrect styling of account bio Co-authored-by: Claire --- app/javascript/mastodon/components/poll.js | 2 +- app/javascript/mastodon/features/account/components/header.js | 2 +- .../mastodon/features/compose/components/reply_indicator.js | 2 +- .../mastodon/features/directory/components/account_card.js | 2 +- .../features/follow_requests/components/account_authorize.js | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/javascript/mastodon/components/poll.js b/app/javascript/mastodon/components/poll.js index 41c99710fc..477f56e130 100644 --- a/app/javascript/mastodon/components/poll.js +++ b/app/javascript/mastodon/components/poll.js @@ -153,7 +153,7 @@ class Poll extends ImmutablePureComponent { } diff --git a/app/javascript/mastodon/features/account/components/header.js b/app/javascript/mastodon/features/account/components/header.js index 0b4431d625..4647b98b21 100644 --- a/app/javascript/mastodon/features/account/components/header.js +++ b/app/javascript/mastodon/features/account/components/header.js @@ -340,7 +340,7 @@ class Header extends ImmutablePureComponent { {account.get('id') !== me && !suspended && } - {account.get('note').length > 0 && account.get('note') !== '

' &&
} + {account.get('note').length > 0 && account.get('note') !== '

' &&
}
{!suspended && ( diff --git a/app/javascript/mastodon/features/compose/components/reply_indicator.js b/app/javascript/mastodon/features/compose/components/reply_indicator.js index 8563838932..a1d5c420cb 100644 --- a/app/javascript/mastodon/features/compose/components/reply_indicator.js +++ b/app/javascript/mastodon/features/compose/components/reply_indicator.js @@ -56,7 +56,7 @@ class ReplyIndicator extends ImmutablePureComponent {
-
+
{status.get('media_attachments').size > 0 && (
diff --git a/app/javascript/mastodon/features/follow_requests/components/account_authorize.js b/app/javascript/mastodon/features/follow_requests/components/account_authorize.js index a3b524db1d..8269f5ae43 100644 --- a/app/javascript/mastodon/features/follow_requests/components/account_authorize.js +++ b/app/javascript/mastodon/features/follow_requests/components/account_authorize.js @@ -35,7 +35,7 @@ class AccountAuthorize extends ImmutablePureComponent { -
+
From bc4efd5e98078946c1d62ad287361246ca571970 Mon Sep 17 00:00:00 2001 From: Daigo 3 Dango Date: Fri, 22 Jan 2021 09:09:40 +0000 Subject: [PATCH 3/7] Use libvpx >= 5 (#15591) Ubuntu 18.04 provides libvpx5 while Ubuntu 20.04 does libvpx6 --- Aptfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aptfile b/Aptfile index 419d159ef6..b2cbad714d 100644 --- a/Aptfile +++ b/Aptfile @@ -22,7 +22,7 @@ libpixman-1-0 librsvg2-2 libthai-data libthai0 -libvpx5 +libvpx[5-9] libxcb-render0 libxcb-shm0 libxrender1 From 7ea9588520c664f17a02265d8456b2288476cb9b Mon Sep 17 00:00:00 2001 From: luigi <007.lva@gmail.com> Date: Fri, 22 Jan 2021 10:28:15 -0500 Subject: [PATCH 4/7] Use Enumerable#filter_map in more places (#15527) --- app/lib/spam_check.rb | 4 ++-- app/presenters/status_relationships_presenter.rb | 2 +- .../activitypub/fetch_featured_collection_service.rb | 7 ++----- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/app/lib/spam_check.rb b/app/lib/spam_check.rb index 68e586d00b..dcb2db9ca9 100644 --- a/app/lib/spam_check.rb +++ b/app/lib/spam_check.rb @@ -186,9 +186,9 @@ class SpamCheck def matching_status_ids if nilsimsa? - other_digests.select { |record| record.start_with?('nilsimsa') && nilsimsa_compare_value(digest, record.split(':')[1]) >= NILSIMSA_COMPARE_THRESHOLD }.filter_map { |record| record.split(':')[2] } + other_digests.filter_map { |record| record.split(':')[2] if record.start_with?('nilsimsa') && nilsimsa_compare_value(digest, record.split(':')[1]) >= NILSIMSA_COMPARE_THRESHOLD } else - other_digests.select { |record| record.start_with?('md5') && record.split(':')[1] == digest }.filter_map { |record| record.split(':')[2] } + other_digests.filter_map { |record| record.split(':')[2] if record.start_with?('md5') && record.split(':')[1] == digest } end end diff --git a/app/presenters/status_relationships_presenter.rb b/app/presenters/status_relationships_presenter.rb index f4849d245b..70fb2ba900 100644 --- a/app/presenters/status_relationships_presenter.rb +++ b/app/presenters/status_relationships_presenter.rb @@ -15,7 +15,7 @@ class StatusRelationshipsPresenter statuses = statuses.compact status_ids = statuses.flat_map { |s| [s.id, s.reblog_of_id] }.uniq.compact conversation_ids = statuses.filter_map(&:conversation_id).uniq - pinnable_status_ids = statuses.map(&:proper).select { |s| s.account_id == current_account_id && %w(public unlisted).include?(s.visibility) }.map(&:id) + pinnable_status_ids = statuses.map(&:proper).filter_map { |s| s.id if s.account_id == current_account_id && %w(public unlisted).include?(s.visibility) } @reblogs_map = Status.reblogs_map(status_ids, current_account_id).merge(options[:reblogs_map] || {}) @favourites_map = Status.favourites_map(status_ids, current_account_id).merge(options[:favourites_map] || {}) diff --git a/app/services/activitypub/fetch_featured_collection_service.rb b/app/services/activitypub/fetch_featured_collection_service.rb index 82c861f5b8..72352aca6f 100644 --- a/app/services/activitypub/fetch_featured_collection_service.rb +++ b/app/services/activitypub/fetch_featured_collection_service.rb @@ -23,11 +23,8 @@ class ActivityPub::FetchFeaturedCollectionService < BaseService def process_items(items) status_ids = items.map { |item| value_or_id(item) } - .reject { |uri| ActivityPub::TagManager.instance.local_uri?(uri) } - .filter_map { |uri| ActivityPub::FetchRemoteStatusService.new.call(uri) } - .select { |status| status.account_id == @account.id } - .map(&:id) - + .filter_map { |uri| ActivityPub::FetchRemoteStatusService.new.call(uri) unless ActivityPub::TagManager.instance.local_uri?(uri) } + .filter_map { |status| status.id if status.account_id == @account.id } to_remove = [] to_add = status_ids From 3ca089d4d76205b064c0ef17d13cb5003927fa2a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 23 Jan 2021 23:25:08 +0900 Subject: [PATCH 5/7] Bump makara from 0.4.1 to 0.5.0 (#15578) Bumps [makara](https://github.com/taskrabbit/makara) from 0.4.1 to 0.5.0. - [Release notes](https://github.com/taskrabbit/makara/releases) - [Changelog](https://github.com/instacart/makara/blob/master/CHANGELOG.md) - [Commits](https://github.com/taskrabbit/makara/compare/v0.4.1...v0.5.0) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Gemfile | 2 +- Gemfile.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index f32e00ec88..aeb6d73ee7 100644 --- a/Gemfile +++ b/Gemfile @@ -13,7 +13,7 @@ gem 'rack', '~> 2.2.3' gem 'hamlit-rails', '~> 0.2' gem 'pg', '~> 1.2' -gem 'makara', '~> 0.4' +gem 'makara', '~> 0.5' gem 'pghero', '~> 2.7' gem 'dotenv-rails', '~> 2.7' diff --git a/Gemfile.lock b/Gemfile.lock index 38174e0f7e..516db5a321 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -333,7 +333,7 @@ GEM nokogiri (>= 1.5.9) mail (2.7.1) mini_mime (>= 0.1.1) - makara (0.4.1) + makara (0.5.0) activerecord (>= 3.0.0) marcel (0.3.3) mimemagic (~> 0.3.2) @@ -740,7 +740,7 @@ DEPENDENCIES letter_opener_web (~> 1.4) link_header (~> 0.0) lograge (~> 0.11) - makara (~> 0.4) + makara (~> 0.5) mario-redis-lock (~> 1.2) memory_profiler microformats (~> 4.2) From 4f05a43f8fe1396b12efc14115a628751dafe5d4 Mon Sep 17 00:00:00 2001 From: Joe <401283+HTMLbyJoe@users.noreply.github.com> Date: Sun, 24 Jan 2021 03:14:35 -0500 Subject: [PATCH 6/7] Fix link to documentation repo (#15620) --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f7b8f17ccf..31f0a1319e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -36,4 +36,4 @@ The smaller the set of changes in the pull request is, the quicker it can be rev ## Documentation -The [Mastodon documentation](https://docs.joinmastodon.org) is a statically generated site. You can [submit merge requests to mastodon/docs](https://source.joinmastodon.org/mastodon/docs). +The [Mastodon documentation](https://docs.joinmastodon.org) is a statically generated site. You can [submit merge requests to tootsuite/documentation](https://github.com/tootsuite/documentation). From 7f1c56954b46b26b4dadfa92047f1ee5d7f9ad0a Mon Sep 17 00:00:00 2001 From: Takeshi Umeda Date: Mon, 25 Jan 2021 17:22:41 +0900 Subject: [PATCH 7/7] Fix first return value of FetchLinkCardService.html method (#15630) --- app/services/fetch_link_card_service.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/services/fetch_link_card_service.rb b/app/services/fetch_link_card_service.rb index 255490d5cd..74fe9a0a58 100644 --- a/app/services/fetch_link_card_service.rb +++ b/app/services/fetch_link_card_service.rb @@ -47,11 +47,11 @@ class FetchLinkCardService < BaseService Request.new(:get, @url).add_headers('Accept' => 'text/html', 'User-Agent' => Mastodon::Version.user_agent + ' Bot').perform do |res| if res.code == 200 && res.mime_type == 'text/html' - @html = res.body_with_limit @html_charset = res.charset + @html = res.body_with_limit else - @html = nil @html_charset = nil + @html = nil end end end