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

Commit

Permalink
Merge pull request #993 from mssola/ldap-downcase
Browse files Browse the repository at this point in the history
namespace: convert to downcase first on make_valid
  • Loading branch information
monstermunchkin authored Jul 19, 2016
2 parents 651cae0 + ed99ed1 commit a53a733
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 a53a733

Please sign in to comment.