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

Conflicts:
- `app/validators/status_length_validator.rb`:
  Conflict due to glitch-soc's configurable maximum toot chars.
  Ported upstream changes.
This commit is contained in:
Claire
2021-03-11 16:08:15 +01:00
16 changed files with 116 additions and 204 deletions

View File

@@ -69,7 +69,7 @@ class LanguageDetector
def simplify_text(text)
new_text = remove_html(text)
new_text.gsub!(FetchLinkCardService::URL_PATTERN, '')
new_text.gsub!(FetchLinkCardService::URL_PATTERN, '\1')
new_text.gsub!(Account::MENTION_RE, '')
new_text.gsub!(Tag::HASHTAG_RE) { |string| string.gsub(/[#_]/, '#' => '', '_' => ' ').gsub(/[a-z][A-Z]|[a-zA-Z][\d]/) { |s| s.insert(1, ' ') }.downcase }
new_text.gsub!(/:#{CustomEmoji::SHORTCODE_RE_FRAGMENT}:/, '')

View File

@@ -2,12 +2,13 @@
class FetchLinkCardService < BaseService
URL_PATTERN = %r{
( # $1 URL
(https?:\/\/) # $2 Protocol (required)
(#{Twitter::TwitterText::Regex[:valid_domain]}) # $3 Domain(s)
(?::(#{Twitter::TwitterText::Regex[:valid_port_number]}))? # $4 Port number (optional)
(/#{Twitter::TwitterText::Regex[:valid_url_path]}*)? # $5 URL Path and anchor
(\?#{Twitter::TwitterText::Regex[:valid_url_query_chars]}*#{Twitter::TwitterText::Regex[:valid_url_query_ending_chars]})? # $6 Query String
(#{Twitter::TwitterText::Regex[:valid_url_preceding_chars]}) # $1 preceeding chars
( # $2 URL
(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
(\?#{Twitter::TwitterText::Regex[:valid_url_query_chars]}*#{Twitter::TwitterText::Regex[:valid_url_query_ending_chars]})? # $7 Query String
)
}iox
@@ -63,7 +64,7 @@ class FetchLinkCardService < BaseService
def parse_urls
if @status.local?
urls = @status.text.scan(URL_PATTERN).map { |array| Addressable::URI.parse(array[0]).normalize }
urls = @status.text.scan(URL_PATTERN).map { |array| Addressable::URI.parse(array[1]).normalize }
else
html = Nokogiri::HTML(@status.text)
links = html.css('a')

View File

@@ -15,7 +15,7 @@ class NoteLengthValidator < ActiveModel::EachValidator
return '' if value.nil?
value.dup.tap do |new_text|
new_text.gsub!(FetchLinkCardService::URL_PATTERN, 'x' * 23)
new_text.gsub!(FetchLinkCardService::URL_PATTERN, StatusLengthValidator::URL_PLACEHOLDER)
new_text.gsub!(Account::MENTION_RE, '@\2')
end
end

View File

@@ -2,12 +2,6 @@
class StatusLengthValidator < ActiveModel::Validator
MAX_CHARS = (ENV['MAX_TOOT_CHARS'] || 500).to_i
URL_PATTERN = %r{
(?:
(#{Twitter::TwitterText::Regex[:valid_url_preceding_chars]})
(#{FetchLinkCardService::URL_PATTERN})
)
}iox
URL_PLACEHOLDER = "\1#{'x' * 23}"
def validate(status)
@@ -35,7 +29,7 @@ class StatusLengthValidator < ActiveModel::Validator
return '' if @status.text.nil?
@status.text.dup.tap do |new_text|
new_text.gsub!(URL_PATTERN, URL_PLACEHOLDER)
new_text.gsub!(FetchLinkCardService::URL_PATTERN, URL_PLACEHOLDER)
new_text.gsub!(Account::MENTION_RE, '@\2')
end
end

View File

@@ -51,6 +51,6 @@
%th= t('admin.accounts.most_recent_activity')
%th
%tbody
= render @accounts
= render partial: 'account', collection: @accounts
= paginate @accounts

View File

@@ -20,6 +20,6 @@
= t 'admin.action_logs.empty'
- else
.announcements-list
= render @action_logs
= render partial: 'action_log', collection: @action_logs
= paginate @action_logs

View File

@@ -14,6 +14,6 @@
%th= t('admin.email_domain_blocks.domain')
%th
%tbody
= render @email_domain_blocks
= render partial: 'email_domain_block', collection: @email_domain_blocks
= paginate @email_domain_blocks

View File

@@ -36,6 +36,6 @@
%div.muted-hint.center-text
= t 'admin.instances.empty'
- else
= render @instances
= render partial: 'instance', collection: @instances
= paginate @instances