Skip to content

Commit

Permalink
clean up the version
Browse files Browse the repository at this point in the history
  • Loading branch information
kbukum1 committed Dec 20, 2024
1 parent 0c2b5f9 commit 5f35e1c
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions npm_and_yarn/lib/dependabot/npm_and_yarn/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ 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))
Expand All @@ -71,6 +72,18 @@ def initialize(version)
super(T.must(version))
end

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"
end

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

sig { override.params(version: VersionParameter).returns(Dependabot::NpmAndYarn::Version) }
def self.new(version)
T.cast(super, Dependabot::NpmAndYarn::Version)
Expand Down

0 comments on commit 5f35e1c

Please sign in to comment.