Skip to content

Commit

Permalink
Only validate version metadata on create/change (#4100)
Browse files Browse the repository at this point in the history
Enables backfills to versions with invalid URLs in metadata, such as https://rubygems.org/api/v2/rubygems/podcatcher/versions/3.1.8.json (note the empty wiki metadata in the response)
  • Loading branch information
segiddins committed Sep 29, 2023
1 parent f3b3bdf commit 0523170
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions app/models/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Version < ApplicationRecord # rubocop:disable Metrics/ClassLength
validate :gem_platform_and_number_are_unique, on: :create
validate :original_platform_resolves_to_gem_platform, on: %i[create platform_changed? gem_platform_changed?]
validate :authors_format, on: :create
validate :metadata_links_format
validate :metadata_links_format, if: -> { validation_context == :create || metadata_changed? }
validate :metadata_attribute_length
validate :no_dashes_in_version_number, on: :create

Expand Down Expand Up @@ -463,8 +463,10 @@ def feature_release

def metadata_links_format
Linkset::LINKS.each do |link|
errors.add(:metadata, "['#{link}'] does not appear to be a valid URL") if
metadata[link] && metadata[link] !~ Patterns::URL_VALIDATION_REGEXP
url = metadata[link]
next unless url
next if Patterns::URL_VALIDATION_REGEXP.match?(url)
errors.add(:metadata, "['#{link}'] does not appear to be a valid URL")
end
end

Expand Down

0 comments on commit 0523170

Please sign in to comment.