Commit 23603d56 authored by Mathieu Parent's avatar Mathieu Parent
parent c4aae485
......@@ -125,6 +125,18 @@ module Gitlab
@debian_component_regex ||= %r{#{debian_distribution_regex}}.freeze
end
def helm_channel_regex
@helm_channel_regex ||= %r{\A[-\.\_a-zA-Z0-9]+\z}.freeze
end
def helm_package_regex
@helm_package_regex ||= %r{#{helm_channel_regex}}.freeze
end
def helm_version_regex
@helm_version_regex ||= %r{#{prefixed_semver_regex}}.freeze
end
def unbounded_semver_regex
# See the official regex: https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
......
......@@ -628,6 +628,50 @@ RSpec.describe Gitlab::Regex do
it { is_expected.not_to match('hé') }
end
describe '.helm_channel_regex' do
subject { described_class.helm_channel_regex }
it { is_expected.to match('release') }
it { is_expected.to match('my-repo') }
it { is_expected.to match('my-repo42') }
# Do not allow empty
it { is_expected.not_to match('') }
# Do not allow Unicode
it { is_expected.not_to match('hé') }
end
describe '.helm_package_regex' do
subject { described_class.helm_package_regex }
it { is_expected.to match('release') }
it { is_expected.to match('my-repo') }
it { is_expected.to match('my-repo42') }
# Do not allow empty
it { is_expected.not_to match('') }
# Do not allow Unicode
it { is_expected.not_to match('hé') }
it { is_expected.not_to match('my/../repo') }
it { is_expected.not_to match('me%2f%2e%2e%2f') }
end
describe '.helm_version_regex' do
subject { described_class.helm_version_regex }
it { is_expected.to match('v1.2.3') }
it { is_expected.to match('v1.2.3-beta') }
it { is_expected.to match('v1.2.3-alpha.3') }
it { is_expected.not_to match('v1') }
it { is_expected.not_to match('v1.2') }
it { is_expected.not_to match('v1./2.3') }
it { is_expected.not_to match('v../../../../../1.2.3') }
it { is_expected.not_to match('v%2e%2e%2f1.2.3') }
end
describe '.semver_regex' do
subject { described_class.semver_regex }
......
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