]> source.dussan.org Git - redmine.git/commitdiff
Fixed: SVN errors lead to svn username/password being displayed to end users (#1368).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 6 Jun 2008 14:37:49 +0000 (14:37 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 6 Jun 2008 14:37:49 +0000 (14:37 +0000)
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1493 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/redmine/scm/adapters/abstract_adapter.rb

index 8fbae9ff8027ce2ffa8a4593bfb0187547163581..9563ed800894f7ebc4112ebf4a2044891a9dde8a 100644 (file)
@@ -118,7 +118,7 @@ module Redmine
         def logger
           RAILS_DEFAULT_LOGGER
         end
-      
+        
         def shellout(cmd, &block)
           logger.debug "Shelling out: #{cmd}" if logger && logger.debug?
           begin
@@ -127,11 +127,22 @@ module Redmine
               block.call(io) if block_given?
             end
           rescue Errno::ENOENT => e
+            msg = strip_credential(e.message)
             # The command failed, log it and re-raise
-            logger.error("SCM command failed: #{cmd}\n  with: #{e.message}")
-            raise CommandFailed.new(e.message)
+            logger.error("SCM command failed: #{strip_credential(cmd)}\n  with: #{msg}")
+            raise CommandFailed.new(msg)
           end
         end  
+        
+        # Hides username/password in a given command
+        def self.hide_credential(cmd)
+          q = (RUBY_PLATFORM =~ /mswin/ ? '"' : "'")
+          cmd.to_s.gsub(/(\-\-(password|username))\s+(#{q}[^#{q}]+#{q}|[^#{q}]\S+)/, '\\1 xxxx')
+        end
+        
+        def strip_credential(cmd)
+          self.class.hide_credential(cmd)
+        end
       end
       
       class Entries < Array