Fix ClassicIdentifierSuggestionGenerator to reject all-numeric slugs

This commit is contained in:
Tomas Hykel
2026-05-17 15:07:22 +02:00
parent b606031356
commit 4e5ae54077
2 changed files with 13 additions and 1 deletions
@@ -67,8 +67,12 @@ module ProjectIdentifiers
private
BLANK_SLUG_SUBSTITUTIONS = { "." => "dot", "!" => "bang" }.freeze
def slugify(name)
name.to_url.first(Projects::Identifier::CLASSIC_IDENTIFIER_MAX_LENGTH).presence
slug = name.to_url.first(Projects::Identifier::CLASSIC_IDENTIFIER_MAX_LENGTH).presence
slug ||= BLANK_SLUG_SUBSTITUTIONS[name]
slug if slug && Projects::Identifier::CLASSIC_IDENTIFIER_FORMAT.match?(slug)
end
def fallback_base
@@ -63,6 +63,14 @@ RSpec.describe ProjectIdentifiers::ClassicIdentifierSuggestionGenerator do
it "falls back to a randomised project-XXXXXX identifier" do
expect(described_class.new.suggest_identifier("!!!")).to match(/\Aproject-[a-z0-9]{5}\z/)
end
it "maps '.' to 'dot'" do
expect(described_class.new.suggest_identifier(".")).to eq("dot")
end
it "maps '!' to 'bang'" do
expect(described_class.new.suggest_identifier("!")).to eq("bang")
end
end
context "when the name is all-numeric" do