Skip to content

Commit

Permalink
Fix min_id and max_id causing error in search API
Browse files Browse the repository at this point in the history
  • Loading branch information
Gargron committed Nov 12, 2024
1 parent 884bbf7 commit 7b5a93c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
18 changes: 6 additions & 12 deletions app/lib/search_query_transformer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,15 @@ def initialize(prefix, operator, term, options = {})
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
Expand Down Expand Up @@ -222,16 +222,10 @@ def language_code_from_term(term)

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) # This will raise Date::Error if the date is invalid
term
end
end

Expand Down
1 change: 0 additions & 1 deletion lib/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class HostValidationError < ValidationError; end
class LengthValidationError < ValidationError; end
class DimensionsValidationError < ValidationError; end
class StreamValidationError < ValidationError; end
class FilterValidationError < ValidationError; end
class RaceConditionError < Error; end
class RateLimitExceededError < Error; end
class SyntaxError < Error; end
Expand Down

0 comments on commit 7b5a93c

Please sign in to comment.