@@ -484,13 +484,18 @@ protected function startMysqlDumpProcess(array $config, string $dumpPath)
484484 protected function startPostgresDumpProcess (array $ config , string $ dumpPath )
485485 {
486486 $ pgpassFile = tempnam (sys_get_temp_dir (), 'pgpass_ ' );
487+ $ escape = function ($ value ) {
488+ $ value = (string ) $ value ;
489+ // Escape backslashes and colons for .pgpass format
490+ return str_replace (['\\' , ': ' ], ['\\\\' , '\\: ' ], $ value );
491+ };
487492 $ pgpassContent = sprintf (
488493 "%s:%s:%s:%s:%s \n" ,
489- $ config ['host ' ],
490- $ config ['port ' ] ?? 5432 ,
491- $ config ['database ' ],
492- $ config ['username ' ],
493- $ config ['password ' ]
494+ $ escape ( $ config ['host ' ]) ,
495+ $ escape ( $ config ['port ' ] ?? 5432 ) ,
496+ $ escape ( $ config ['database ' ]) ,
497+ $ escape ( $ config ['username ' ]) ,
498+ $ escape ( $ config ['password ' ])
494499 );
495500
496501 file_put_contents ($ pgpassFile , $ pgpassContent );
@@ -695,13 +700,18 @@ protected function createPostgresDump(array $config, string $dumpPath): void
695700 {
696701 // Create temporary .pgpass file for secure password handling
697702 $ pgpassFile = tempnam (sys_get_temp_dir (), 'pgpass_ ' );
703+ $ escape = function ($ value ) {
704+ $ value = (string ) $ value ;
705+ // Escape backslashes and colons for .pgpass format
706+ return str_replace (['\\' , ': ' ], ['\\\\' , '\\: ' ], $ value );
707+ };
698708 $ pgpassContent = sprintf (
699709 "%s:%s:%s:%s:%s \n" ,
700- $ config ['host ' ],
701- $ config ['port ' ] ?? 5432 ,
702- $ config ['database ' ],
703- $ config ['username ' ],
704- $ config ['password ' ]
710+ $ escape ( $ config ['host ' ]) ,
711+ $ escape ( $ config ['port ' ] ?? 5432 ) ,
712+ $ escape ( $ config ['database ' ]) ,
713+ $ escape ( $ config ['username ' ]) ,
714+ $ escape ( $ config ['password ' ])
705715 );
706716
707717 file_put_contents ($ pgpassFile , $ pgpassContent );
0 commit comments