Skip to content

Commit

Permalink
move removing v into version cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
kbukum1 committed Dec 20, 2024
1 parent a56e1ed commit 64bc0a0
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions npm_and_yarn/lib/dependabot/npm_and_yarn/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ def self.semver_for(version)
sig { override.params(version: VersionParameter).void }
def initialize(version)
version = clean_version(version)

@version_string = T.let(version.to_s, String)
version = version.gsub(/^v/, "") if version.is_a?(String)

@build_info = T.let(nil, T.nilable(String))

version, @build_info = version.to_s.split("+") if version.to_s.include?("+")
Expand All @@ -74,10 +75,13 @@ def initialize(version)

sig { params(version: VersionParameter).returns(VersionParameter) }
def clean_version(version)
# Check if version is a string before attempting to match
# Matches @ followed by x.y.z (digits separated by dots)
if version.is_a?(String) && (match = version.match(/@(\d+\.\d+\.\d+)/))
return match[1] # Just "4.5.3"
if version.is_a?(String)
# Check if version is a string before attempting to match
# Matches @ followed by x.y.z (digits separated by dots)
if (match = version.match(/@(\d+\.\d+\.\d+)/))
version = match[1] # Just "4.5.3"
end
version = version.gsub(/^v/, "") if version.is_a?(String)
end

# If version is not a string or no match found, return original version
Expand Down

0 comments on commit 64bc0a0

Please sign in to comment.