Permalink
Browse files

better escaping (quote the quotes too ;)

  • Loading branch information...
1 parent 71e2467 commit 81220626574103ff176907a13028e2c154d8b42c @vitaly vitaly committed Dec 21, 2009
Showing with 13 additions and 11 deletions.
  1. +2 −0 CHANGELOG
  2. +9 −9 examples/unit/mysqldump_example.rb
  3. +2 −2 lib/astrails/safe/mysqldump.rb
View
@@ -1,3 +1,5 @@
+* quote values in mysql password file
+
0.2.6
* fix typo in the template config file. (change option to options in pgdump)
@@ -2,7 +2,7 @@
describe Astrails::Safe::Mysqldump do
- def def_config
+ def def_config(extra = {})
{
:options => "OPTS",
:user => "User",
@@ -11,7 +11,7 @@ def def_config
:port => 7777,
:socket => "socket",
:skip_tables => [:bar, :baz]
- }
+ }.merge(extra)
end
def mysqldump(id = :foo, config = def_config)
@@ -66,17 +66,17 @@ def mysqldump(id = :foo, config = def_config)
end
describe :mysql_password_file do
- it "should create passwords file with quoted values" do
- m = mysqldump
+ it "should create passwords file with quoted values", :focused => true do
+ m = mysqldump(:foo, def_config(:password => '#qwe"asd\'zxc'))
file = m.send(:mysql_password_file)
File.exists?(file).should == true
File.read(file).should == <<-PWD
[mysqldump]
-user = 'User'
-password = 'pwd'
-socket = 'socket'
-host = 'localhost'
-port = '7777'
+user = "User"
+password = "#qwe\\"asd'zxc"
+socket = "socket"
+host = "localhost"
+port = 7777
PWD
end
end
@@ -15,8 +15,8 @@ def mysql_password_file
file.puts "[mysqldump]"
%w/user password socket host port/.each do |k|
v = @config[k]
- # values are quoted to enclose comment characters ('#')
- file.puts "#{k} = '#{v}'" if v
+ # values are quoted if needed
+ file.puts "#{k} = #{v.inspect}" if v
end
end
end

0 comments on commit 8122062

Please sign in to comment.