OSDN Git Service

Quote subversion username and password in svn commands.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 19 Oct 2007 17:59:59 +0000 (17:59 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 19 Oct 2007 17:59:59 +0000 (17:59 +0000)
git-svn-id: http://redmine.rubyforge.org/svn/trunk@852 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/redmine/scm/adapters/abstract_adapter.rb
lib/redmine/scm/adapters/subversion_adapter.rb

index 04f1d53..4b524c5 100644 (file)
@@ -81,6 +81,14 @@ module Redmine
           path ||= ''
           (path[0,1]!="/") ? "/#{path}" : path
         end
+        
+        def shell_quote(str)
+          if RUBY_PLATFORM =~ /mswin/
+            '"' + str.gsub(/"/, '\\"') + '"'
+          else
+            "'" + str.gsub(/'/, "'\"'\"'") + "'"
+          end
+        end
               
       private
         def retrieve_root_url
index c9a73dd..9e8acce 100644 (file)
@@ -29,7 +29,7 @@ module Redmine
         # Get info about the svn repository\r
         def info\r
           cmd = "#{SVN_BIN} info --xml #{target('')}"\r
-          cmd << " --username #{@login} --password #{@password}" if @login\r
+          cmd << credentials_string\r
           info = nil\r
           shellout(cmd) do |io|\r
             begin\r
@@ -65,7 +65,7 @@ module Redmine
           identifier = 'HEAD' unless identifier and identifier > 0\r
           entries = Entries.new\r
           cmd = "#{SVN_BIN} list --xml #{target(path)}@#{identifier}"\r
-          cmd << " --username #{@login} --password #{@password}" if @login\r
+          cmd << credentials_string\r
           cmd << " 2>&1"\r
           shellout(cmd) do |io|\r
             output = io.read\r
@@ -101,7 +101,7 @@ module Redmine
           identifier_to = 1 unless identifier_to and identifier_to.to_i > 0\r
           revisions = Revisions.new\r
           cmd = "#{SVN_BIN} log --xml -r #{identifier_from}:#{identifier_to}"\r
-          cmd << " --username #{@login} --password #{@password}" if @login\r
+          cmd << credentials_string\r
           cmd << " --verbose " if  options[:with_paths]\r
           cmd << target(path)\r
           shellout(cmd) do |io|\r
@@ -145,7 +145,7 @@ module Redmine
           cmd << "#{identifier_to}:"\r
           cmd << "#{identifier_from}"\r
           cmd << "#{target(path)}@#{identifier_from}"\r
-          cmd << " --username #{@login} --password #{@password}" if @login\r
+          cmd << credentials_string\r
           diff = []\r
           shellout(cmd) do |io|\r
             io.each_line do |line|\r
@@ -161,7 +161,7 @@ module Redmine
         def cat(path, identifier=nil)\r
           identifier = (identifier and identifier.to_i > 0) ? identifier.to_i : "HEAD"\r
           cmd = "#{SVN_BIN} cat #{target(path)}@#{identifier}"\r
-          cmd << " --username #{@login} --password #{@password}" if @login\r
+          cmd << credentials_string\r
           cat = nil\r
           shellout(cmd) do |io|\r
             io.binmode\r
@@ -172,6 +172,15 @@ module Redmine
         rescue Errno::ENOENT => e\r
           raise CommandFailed    \r
         end\r
+        \r
+        private\r
+        \r
+        def credentials_string\r
+          str = ''\r
+          str << " --username #{shell_quote(@login)}" unless @login.blank?\r
+          str << " --password #{shell_quote(@password)}" unless @login.blank? || @password.blank?\r
+          str\r
+        end\r
       end\r
     end\r
   end\r