Merge commit '13ab4b54e2' into upstream-20241204-15

This commit is contained in:
KMY 2024-12-04 08:37:37 +09:00
commit a6a237bc8e
228 changed files with 2678 additions and 1266 deletions

View file

@ -282,6 +282,8 @@ class SearchQueryTransformer < Parslet::Transform
end
class PrefixClause
EPOCH_RE = /\A\d+\z/
attr_reader :operator, :prefix, :term
def initialize(prefix, operator, term, options = {}) # rubocop:disable Metrics/CyclomaticComplexity
@ -311,15 +313,15 @@ class SearchQueryTransformer < Parslet::Transform
when 'before'
@filter = :created_at
@type = :range
@term = { lt: TermValidator.validate_date!(term), time_zone: @options[:current_account]&.user_time_zone.presence || 'UTC' }
@term = { lt: date_from_term(term), time_zone: @options[:current_account]&.user_time_zone.presence || 'UTC' }
when 'after'
@filter = :created_at
@type = :range
@term = { gt: TermValidator.validate_date!(term), time_zone: @options[:current_account]&.user_time_zone.presence || 'UTC' }
@term = { gt: date_from_term(term), time_zone: @options[:current_account]&.user_time_zone.presence || 'UTC' }
when 'during'
@filter = :created_at
@type = :range
@term = { gte: TermValidator.validate_date!(term), lte: TermValidator.validate_date!(term), time_zone: @options[:current_account]&.user_time_zone.presence || 'UTC' }
@term = { gte: date_from_term(term), lte: date_from_term(term), time_zone: @options[:current_account]&.user_time_zone.presence || 'UTC' }
when 'in'
@operator = :flag
@term = term
@ -409,16 +411,10 @@ class SearchQueryTransformer < Parslet::Transform
term
end
end
class TermValidator
STRICT_DATE_REGEX = /\A\d{4}-\d{2}-\d{2}\z/ # yyyy-MM-dd
EPOCH_MILLIS_REGEX = /\A\d{1,19}\z/
def self.validate_date!(value)
return value if value.match?(STRICT_DATE_REGEX) || value.match?(EPOCH_MILLIS_REGEX)
raise Mastodon::FilterValidationError, "Invalid date #{value}"
def date_from_term(term)
DateTime.iso8601(term) unless term.match?(EPOCH_RE) # This will raise Date::Error if the date is invalid
term
end
end