Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/packages/package.rb')
-rw-r--r--app/models/packages/package.rb17
1 files changed, 16 insertions, 1 deletions
diff --git a/app/models/packages/package.rb b/app/models/packages/package.rb
index 7744e578df5..90a1bb4bc69 100644
--- a/app/models/packages/package.rb
+++ b/app/models/packages/package.rb
@@ -103,7 +103,15 @@ class Packages::Package < ApplicationRecord
scope :for_projects, ->(project_ids) { where(project_id: project_ids) }
scope :with_name, ->(name) { where(name: name) }
scope :with_name_like, ->(name) { where(arel_table[:name].matches(name)) }
- scope :with_normalized_pypi_name, ->(name) { where("LOWER(regexp_replace(name, '[-_.]+', '-', 'g')) = ?", name.downcase) }
+
+ scope :with_normalized_pypi_name, ->(name) do
+ where(
+ "LOWER(regexp_replace(name, ?, '-', 'g')) = ?",
+ Gitlab::Regex::Packages::PYPI_NORMALIZED_NAME_REGEX_STRING,
+ name.downcase
+ )
+ end
+
scope :search_by_name, ->(query) { fuzzy_search(query, [:name], use_minimum_char_limit: false) }
scope :with_version, ->(version) { where(version: version) }
scope :without_version_like, -> (version) { where.not(arel_table[:version].matches(version)) }
@@ -315,6 +323,13 @@ class Packages::Package < ApplicationRecord
::Packages::MarkPackageFilesForDestructionWorker.perform_async(id)
end
+ # As defined in PEP 503 https://peps.python.org/pep-0503/#normalized-names
+ def normalized_pypi_name
+ return name unless pypi?
+
+ name.gsub(/#{Gitlab::Regex::Packages::PYPI_NORMALIZED_NAME_REGEX_STRING}/, '-').downcase
+ end
+
private
def composer_tag_version?