Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
namespace: convert to downcase first on make_valid
Browse files Browse the repository at this point in the history
One usual pain point that can be solved in `make_valid` is that lots of times
the problem is with the case. Since upper case is not accepted in namespace
names, then it will be converted weirdly. Because of this, from now on the
first thing that `make_valid` will do if the name doesn't match right away, is
to convert the name to downcase. With this commit then, something like `Miquel`
will be converted to `miquel`, instead of `_iquel`, which makes more sense.

See #965

Signed-off-by: Miquel Sabaté Solà <[email protected]>
  • Loading branch information
mssola committed Jul 18, 2016
1 parent 63971b4 commit ed99ed1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/models/namespace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,12 @@ def self.get_from_name(name, registry = nil)
def self.make_valid(name)
return name if name =~ NAME_REGEXP

# First of all we strip extra characters from the beginning and end.
# One common case is LDAP and case sensitivity. With this in mind, try to
# downcase everything and see if now it's fine.
name = name.downcase
return name if name =~ NAME_REGEXP

# Let's strip extra characters from the beginning and end.
first = name.index(/[a-z0-9]/)
return nil if first.nil?
last = name.rindex(/[a-z0-9]/)
Expand Down
4 changes: 4 additions & 0 deletions spec/models/namespace_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@
expect(Namespace.make_valid("ma_s")).to eq "ma_s"
expect(Namespace.make_valid("!lol!")).to eq "lol"
expect(Namespace.make_valid("!lol!name")).to eq "lol_name"
expect(Namespace.make_valid("Miquel.Sabate")).to eq "miquel.sabate"
expect(Namespace.make_valid("Miquel.Sabate.")).to eq "miquel.sabate"
expect(Namespace.make_valid("M")).to eq "m"
expect(Namespace.make_valid("_M_")).to eq "m"
end
end
end

0 comments on commit ed99ed1

Please sign in to comment.