Commit 66fd9bdb authored by Mark Chao's avatar Mark Chao

Merge branch '342572-nuget-regex-short' into 'master'

Update nuget version regex

See merge request gitlab-org/gitlab!77543
parents 6699578e d1f2e41a
......@@ -79,7 +79,11 @@ module Gitlab
def nuget_version_regex
@nuget_version_regex ||= /
\A#{_semver_major_minor_patch_regex}(\.\d*)?#{_semver_prerelease_build_regex}\z
\A#{_semver_major_regex}
\.#{_semver_minor_regex}
(\.#{_semver_patch_regex})?
(\.\d*)?
#{_semver_prerelease_build_regex}\z
/x.freeze
end
......@@ -167,9 +171,25 @@ module Gitlab
# regexes rather than being used alone.
def _semver_major_minor_patch_regex
@_semver_major_minor_patch_regex ||= /
#{_semver_major_regex}\.#{_semver_minor_regex}\.#{_semver_patch_regex}
/x.freeze
end
def _semver_major_regex
@_semver_major_regex ||= /
(?<major>0|[1-9]\d*)
\.(?<minor>0|[1-9]\d*)
\.(?<patch>0|[1-9]\d*)
/x.freeze
end
def _semver_minor_regex
@_semver_minor_regex ||= /
(?<minor>0|[1-9]\d*)
/x.freeze
end
def _semver_patch_regex
@_semver_patch_regex ||= /
(?<patch>0|[1-9]\d*)
/x.freeze
end
......
......@@ -433,6 +433,7 @@ RSpec.describe Gitlab::Regex do
describe '.nuget_version_regex' do
subject { described_class.nuget_version_regex }
it { is_expected.to match('1.2') }
it { is_expected.to match('1.2.3') }
it { is_expected.to match('1.2.3.4') }
it { is_expected.to match('1.2.3.4-stable.1') }
......@@ -440,7 +441,6 @@ RSpec.describe Gitlab::Regex do
it { is_expected.to match('1.2.3-alpha.3') }
it { is_expected.to match('1.0.7+r3456') }
it { is_expected.not_to match('1') }
it { is_expected.not_to match('1.2') }
it { is_expected.not_to match('1./2.3') }
it { is_expected.not_to match('../../../../../1.2.3') }
it { is_expected.not_to match('%2e%2e%2f1.2.3') }
......
......@@ -413,9 +413,17 @@ RSpec.describe Packages::Package, type: :model do
it_behaves_like 'validating version to be SemVer compliant for', :terraform_module_package
context 'nuget package' do
it_behaves_like 'validating version to be SemVer compliant for', :nuget_package
subject { build_stubbed(:nuget_package) }
it { is_expected.to allow_value('1.2').for(:version) }
it { is_expected.to allow_value('1.2.3').for(:version) }
it { is_expected.to allow_value('1.2.3.4').for(:version) }
it { is_expected.to allow_value('1.2.3-beta').for(:version) }
it { is_expected.to allow_value('1.2.3-alpha.3').for(:version) }
it { is_expected.not_to allow_value('1').for(:version) }
it { is_expected.not_to allow_value('1./2.3').for(:version) }
it { is_expected.not_to allow_value('../../../../../1.2.3').for(:version) }
it { is_expected.not_to allow_value('%2e%2e%2f1.2.3').for(:version) }
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment