Merge branch 'main' into glitch-soc/merge-upstream

Conflicts:
- `CONTRIBUTING.md`:
  Not a real conflict, glitch-soc quotes the upstream file, which has been
  changed. Update the quote.
master
Claire 3 years ago
commit b81710c02c
  1. 2
      Aptfile
  2. 2
      CONTRIBUTING.md
  3. 2
      Gemfile
  4. 4
      Gemfile.lock
  5. 2
      app/javascript/mastodon/components/poll.js
  6. 2
      app/javascript/mastodon/features/account/components/header.js
  7. 2
      app/javascript/mastodon/features/compose/components/reply_indicator.js
  8. 2
      app/javascript/mastodon/features/directory/components/account_card.js
  9. 2
      app/javascript/mastodon/features/follow_requests/components/account_authorize.js
  10. 8
      app/lib/extractor.rb
  11. 6
      app/lib/feed_manager.rb
  12. 2
      app/lib/formatter.rb
  13. 2
      app/lib/request.rb
  14. 6
      app/lib/sanitize_config.rb
  15. 4
      app/lib/spam_check.rb
  16. 2
      app/models/concerns/omniauthable.rb
  17. 2
      app/presenters/status_relationships_presenter.rb
  18. 2
      app/services/account_search_service.rb
  19. 7
      app/services/activitypub/fetch_featured_collection_service.rb
  20. 4
      app/services/fetch_link_card_service.rb
  21. 2
      app/services/search_service.rb
  22. 2
      app/validators/blacklisted_email_validator.rb
  23. 2
      app/validators/html_validator.rb
  24. 2
      config/initializers/open_uri_redirection.rb
  25. 2
      config/initializers/rack_attack.rb
  26. 2
      lib/mastodon/domains_cli.rb

@ -22,7 +22,7 @@ libpixman-1-0
librsvg2-2 librsvg2-2
libthai-data libthai-data
libthai0 libthai0
libvpx5 libvpx[5-9]
libxcb-render0 libxcb-render0
libxcb-shm0 libxcb-shm0
libxrender1 libxrender1

@ -70,6 +70,6 @@ The smaller the set of changes in the pull request is, the quicker it can be rev
## Documentation ## 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).
</blockquote> </blockquote>

@ -13,7 +13,7 @@ gem 'rack', '~> 2.2.3'
gem 'hamlit-rails', '~> 0.2' gem 'hamlit-rails', '~> 0.2'
gem 'pg', '~> 1.2' gem 'pg', '~> 1.2'
gem 'makara', '~> 0.4' gem 'makara', '~> 0.5'
gem 'pghero', '~> 2.7' gem 'pghero', '~> 2.7'
gem 'dotenv-rails', '~> 2.7' gem 'dotenv-rails', '~> 2.7'

@ -333,7 +333,7 @@ GEM
nokogiri (>= 1.5.9) nokogiri (>= 1.5.9)
mail (2.7.1) mail (2.7.1)
mini_mime (>= 0.1.1) mini_mime (>= 0.1.1)
makara (0.4.1) makara (0.5.0)
activerecord (>= 3.0.0) activerecord (>= 3.0.0)
marcel (0.3.3) marcel (0.3.3)
mimemagic (~> 0.3.2) mimemagic (~> 0.3.2)
@ -741,7 +741,7 @@ DEPENDENCIES
letter_opener_web (~> 1.4) letter_opener_web (~> 1.4)
link_header (~> 0.0) link_header (~> 0.0)
lograge (~> 0.11) lograge (~> 0.11)
makara (~> 0.4) makara (~> 0.5)
mario-redis-lock (~> 1.2) mario-redis-lock (~> 1.2)
memory_profiler memory_profiler
microformats (~> 4.2) microformats (~> 4.2)

@ -153,7 +153,7 @@ class Poll extends ImmutablePureComponent {
</span>} </span>}
<span <span
className='poll__option__text' className='poll__option__text translate'
dangerouslySetInnerHTML={{ __html: titleEmojified }} dangerouslySetInnerHTML={{ __html: titleEmojified }}
/> />

@ -340,7 +340,7 @@ class Header extends ImmutablePureComponent {
{account.get('id') !== me && !suspended && <AccountNoteContainer account={account} />} {account.get('id') !== me && !suspended && <AccountNoteContainer account={account} />}
{account.get('note').length > 0 && account.get('note') !== '<p></p>' && <div className='account__header__content' dangerouslySetInnerHTML={content} className='translate' />} {account.get('note').length > 0 && account.get('note') !== '<p></p>' && <div className='account__header__content translate' dangerouslySetInnerHTML={content} />}
</div> </div>
{!suspended && ( {!suspended && (

@ -56,7 +56,7 @@ class ReplyIndicator extends ImmutablePureComponent {
</a> </a>
</div> </div>
<div className='reply-indicator__content' dangerouslySetInnerHTML={content} /> <div className='reply-indicator__content translate' dangerouslySetInnerHTML={content} />
{status.get('media_attachments').size > 0 && ( {status.get('media_attachments').size > 0 && (
<AttachmentList <AttachmentList

@ -241,7 +241,7 @@ class AccountCard extends ImmutablePureComponent {
<div className='directory__card__extra' ref={this.setRef}> <div className='directory__card__extra' ref={this.setRef}>
<div <div
className='account__header__content' className='account__header__content translate'
dangerouslySetInnerHTML={{ __html: account.get('note_emojified') }} dangerouslySetInnerHTML={{ __html: account.get('note_emojified') }}
/> />
</div> </div>

@ -35,7 +35,7 @@ class AccountAuthorize extends ImmutablePureComponent {
<DisplayName account={account} /> <DisplayName account={account} />
</Permalink> </Permalink>
<div className='account__header__content' dangerouslySetInnerHTML={content} /> <div className='account__header__content translate' dangerouslySetInnerHTML={content} />
</div> </div>
<div className='account--panel'> <div className='account--panel'>

@ -7,14 +7,14 @@ module Extractor
# :yields: username, list_slug, start, end # :yields: username, list_slug, start, end
def extract_mentions_or_lists_with_indices(text) 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 = [] possible_entries = []
text.to_s.scan(Account::MENTION_RE) do |screen_name, _| text.to_s.scan(Account::MENTION_RE) do |screen_name, _|
match_data = $LAST_MATCH_INFO match_data = $LAST_MATCH_INFO
after = $' after = $'
unless after =~ Twitter::Regex[:end_mention_match] unless Twitter::Regex[:end_mention_match].match?(after)
start_position = match_data.char_begin(1) - 1 start_position = match_data.char_begin(1) - 1
end_position = match_data.char_end(1) end_position = match_data.char_end(1)
possible_entries << { possible_entries << {
@ -33,7 +33,7 @@ module Extractor
end end
def extract_hashtags_with_indices(text, **) def extract_hashtags_with_indices(text, **)
return [] unless text =~ /#/ return [] unless /#/.match?(text)
tags = [] tags = []
text.scan(Tag::HASHTAG_RE) do |hash_text, _| text.scan(Tag::HASHTAG_RE) do |hash_text, _|
@ -41,7 +41,7 @@ module Extractor
start_position = match_data.char_begin(1) - 1 start_position = match_data.char_begin(1) - 1
end_position = match_data.char_end(1) end_position = match_data.char_end(1)
after = $' after = $'
if after =~ %r{\A://} if %r{\A://}.match?(after)
hash_text.match(/(.+)(https?\Z)/) do |matched| hash_text.match(/(.+)(https?\Z)/) do |matched|
hash_text = matched[1] hash_text = matched[1]
end_position -= matched[2].char_length end_position -= matched[2].char_length

@ -454,8 +454,8 @@ class FeedManager
active_filters.map! do |filter| active_filters.map! do |filter|
if filter.whole_word if filter.whole_word
sb = filter.phrase =~ /\A[[:word:]]/ ? '\b' : '' sb = /\A[[:word:]]/.match?(filter.phrase) ? '\b' : ''
eb = filter.phrase =~ /[[:word:]]\z/ ? '\b' : '' eb = /[[:word:]]\z/.match?(filter.phrase) ? '\b' : ''
/(?mix:#{sb}#{Regexp.escape(filter.phrase)}#{eb})/ /(?mix:#{sb}#{Regexp.escape(filter.phrase)}#{eb})/
else else
@ -475,7 +475,7 @@ class FeedManager
status.media_attachments.map(&:description).join("\n\n"), status.media_attachments.map(&:description).join("\n\n"),
].compact.join("\n\n") ].compact.join("\n\n")
!combined_regex.match(combined_text).nil? combined_regex.match?(combined_text)
end end
# Adds a status to an account's feed, returning true if a status was # Adds a status to an account's feed, returning true if a status was

@ -287,7 +287,7 @@ class Formatter
escaped = text.chars.map do |c| escaped = text.chars.map do |c|
output = begin 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) CGI.escape(c)
else else
c c

@ -145,7 +145,7 @@ class Request
end end
def block_hidden_service? 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 end
module ClientLimit module ClientLimit

@ -28,9 +28,9 @@ class Sanitize
return unless class_list return unless class_list
class_list.keep_if do |e| class_list.keep_if do |e|
next true if e =~ /^(h|p|u|dt|e)-/ # microformats classes next true if /^(h|p|u|dt|e)-/.match?(e) # microformats classes
next true if e =~ /^(mention|hashtag)$/ # semantic classes next true if /^(mention|hashtag)$/.match?(e) # semantic classes
next true if e =~ /^(ellipsis|invisible)$/ # link formatting classes next true if /^(ellipsis|invisible)$/.match?(e) # link formatting classes
end end
node['class'] = class_list.join(' ') node['class'] = class_list.join(' ')

@ -186,9 +186,9 @@ class SpamCheck
def matching_status_ids def matching_status_ids
if nilsimsa? 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 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
end end

@ -57,7 +57,7 @@ module Omniauthable
user = User.new(user_params_from_auth(email, auth)) 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.skip_confirmation!
user.save! user.save!
user user

@ -15,7 +15,7 @@ class StatusRelationshipsPresenter
statuses = statuses.compact statuses = statuses.compact
status_ids = statuses.flat_map { |s| [s.id, s.reblog_of_id] }.uniq.compact status_ids = statuses.flat_map { |s| [s.id, s.reblog_of_id] }.uniq.compact
conversation_ids = statuses.filter_map(&:conversation_id).uniq 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] || {}) @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] || {}) @favourites_map = Status.favourites_map(status_ids, current_account_id).merge(options[:favourites_map] || {})

@ -175,7 +175,7 @@ class AccountSearchService < BaseService
end end
def username_complete? def username_complete?
query.include?('@') && "@#{query}" =~ /\A#{Account::MENTION_RE}\Z/ query.include?('@') && "@#{query}".match?(/\A#{Account::MENTION_RE}\Z/)
end end
def likely_acct? def likely_acct?

@ -23,11 +23,8 @@ class ActivityPub::FetchFeaturedCollectionService < BaseService
def process_items(items) def process_items(items)
status_ids = items.map { |item| value_or_id(item) } 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) unless ActivityPub::TagManager.instance.local_uri?(uri) }
.filter_map { |uri| ActivityPub::FetchRemoteStatusService.new.call(uri) } .filter_map { |status| status.id if status.account_id == @account.id }
.select { |status| status.account_id == @account.id }
.map(&:id)
to_remove = [] to_remove = []
to_add = status_ids to_add = status_ids

@ -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| 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' if res.code == 200 && res.mime_type == 'text/html'
@html = res.body_with_limit
@html_charset = res.charset @html_charset = res.charset
@html = res.body_with_limit
else else
@html = nil
@html_charset = nil @html_charset = nil
@html = nil
end end
end end
end end

@ -72,7 +72,7 @@ class SearchService < BaseService
end end
def url_query? def url_query?
@resolve && @query =~ /\Ahttps?:\/\// @resolve && /\Ahttps?:\/\//.match?(@query)
end end
def url_resource_results def url_resource_results

@ -22,7 +22,7 @@ class BlacklistedEmailValidator < ActiveModel::Validator
domains = Rails.configuration.x.email_domains_blacklist.gsub('.', '\.') domains = Rails.configuration.x.email_domains_blacklist.gsub('.', '\.')
regexp = Regexp.new("@(.+\\.)?(#{domains})", true) regexp = Regexp.new("@(.+\\.)?(#{domains})", true)
@email =~ regexp regexp.match?(@email)
end end
def not_on_whitelist? def not_on_whitelist?

@ -15,6 +15,6 @@ class HtmlValidator < ActiveModel::EachValidator
def html_errors(str) def html_errors(str)
fragment = Nokogiri::HTML.fragment(options[:wrap_with] ? "<#{options[:wrap_with]}>#{str}</#{options[:wrap_with]}>" : str) fragment = Nokogiri::HTML.fragment(options[:wrap_with] ? "<#{options[:wrap_with]}>#{str}</#{options[:wrap_with]}>" : str)
fragment.errors.select { |error| ERROR_RE =~ error.message } fragment.errors.select { |error| ERROR_RE.match?(error.message) }
end end
end end

@ -3,6 +3,6 @@ require 'open-uri'
module OpenURI module OpenURI
def self.redirectable?(uri1, uri2) # :nodoc: def self.redirectable?(uri1, uri2) # :nodoc:
uri1.scheme.casecmp(uri2.scheme).zero? || 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
end end

@ -78,7 +78,7 @@ class Rack::Attack
API_DELETE_STATUS_REGEX = /\A\/api\/v1\/statuses\/[\d]+/.freeze API_DELETE_STATUS_REGEX = /\A\/api\/v1\/statuses\/[\d]+/.freeze
throttle('throttle_api_delete', limit: 30, period: 30.minutes) do |req| 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 end
throttle('throttle_sign_up_attempts/ip', limit: 25, period: 5.minutes) do |req| throttle('throttle_sign_up_attempts/ip', limit: 25, period: 5.minutes) do |req|

@ -93,7 +93,7 @@ module Mastodon
work_unit = ->(domain) do work_unit = ->(domain) do
next if stats.key?(domain) 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 stats[domain] = nil

Loading…
Cancel
Save