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

Improve code readability by explaining a validation regex #156

Merged
merged 1 commit into from
Aug 27, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions bin/gandalf.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ func requestedRepository() (repository.Repository, error) {
// The following format is allowed:
// (git-[a-z-]+) '/?([\w-+@][\w-+.@]*/)?([\w-]+)\.git'
func parseGitCommand() (command, name string, err error) {
// The following regex validates the git command, which is in the form:
// <git-command> [<namespace>/]<name>
// with namespace being optional. If a namespace is used, we validate it
// according to the following:
// - a namespace is optional
// - a namespace contains only alphanumerics, underlines, @´s, -´s, +´s
// and periods but it does not start with a period (.)
// - one and exactly one slash (/) separates namespace and the actual name
r, err := regexp.Compile(`(git-[a-z-]+) '/?([\w-+@][\w-+.@]*/)?([\w-]+)\.git'`)
if err != nil {
panic(err)
Expand Down
12 changes: 8 additions & 4 deletions repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,15 @@ func (r *Repository) ReadOnlyURL() string {
// A valid repository MUST have:
// - a name without any special chars only alphanumeric and underlines are allowed.
// - at least one user in users array
// A valid repository MAY have one namespace since:
// - one slash (/) separates namespace and name
// - a namespace does not start with period
// - a namespace contains ony alphanumeric, underlines @, - and period
// A valid repository MAY have one namespace since the following is obeyed:
// - a namespace is optional
// - a namespace contains only alphanumerics, underlines, @´s, -´s, +´s and
// periods but it does not start with a period (.)
// - one and exactly one slash (/) separates namespace and the actual name
func (r *Repository) isValid() (bool, error) {
// The following regex validates the name of a repository, which may
// contain a namespace. If a namespace is used, we validate it
// accordingly (see comments above)
m, e := regexp.Match(`^([\w-+@][\w-+.@]*/)?[\w-]+$`, []byte(r.Name))
if e != nil {
panic(e)
Expand Down