From 81a6fe6b024529e243be2acf0e916e1bee3f6665 Mon Sep 17 00:00:00 2001 From: Alex Dergachev Date: Wed, 3 Dec 2014 22:50:37 +0000 Subject: [PATCH] Sanitize auto-generated repo identifier; refs #4 Redmine repo identifiers can't have any characters except: /[a-z0-9_-]/ We scan for this and turn everything else into a '-' --- app/models/repository/git_remote.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/models/repository/git_remote.rb b/app/models/repository/git_remote.rb index d328958..4afd783 100644 --- a/app/models/repository/git_remote.rb +++ b/app/models/repository/git_remote.rb @@ -47,13 +47,13 @@ class Repository::GitRemote < Repository::Git def initialize_clone # avoids crash in RepositoriesController#destroy return unless attributes["extra_info"]["extra_clone_url"] - + p = parse(attributes["extra_info"]["extra_clone_url"]) self.identifier = p[:identifier] if identifier.empty? self.url = PATH_PREFIX + p[:path] if url.empty? err = ensure_possibly_empty_clone_exists - errors.add :extra_clone_url, err if err + errors.add :extra_clone_url, err if err end # equality check ignoring trailing whitespace and slashes @@ -101,7 +101,7 @@ class Repository::GitRemote < Repository::Git .gsub(/\.git$/, '') # Remove trailing .git ret[:host] = ret[:path].split('/').first #TODO: handle project uniqueness automatically or prompt - ret[:identifier] = ret[:path].split('/').last.downcase + ret[:identifier] = ret[:path].split('/').last.downcase.gsub(/[^a-z0-9_-]/,'-') return ret end @@ -118,7 +118,6 @@ class Repository::GitRemote < Repository::Git end end - # Checks if host is in ~/.ssh/known_hosts, adds it if not present def self.add_known_host(host) # if not found... @@ -138,5 +137,4 @@ class Repository::GitRemote < Repository::Git end end end - end