PG-allow special characters in user/pw/dbname (#7307)

* PG-handle special chars with encodeURIComponent * PG backup-don't use dbname in dumpfile

PTR committed Sep 29, 2025 at 19:58 UTC 63092f16c11797f6047303494cd4a65db6fc60e2
1 file changed +6 -6
db.js
+6 -6
@@ -950,7 +950,7 @@ module.exports.CreateDB = function (parent, func) {
950 });
951 } else { // If not present, create the tables and indexes
952 //not needed, just use a create db statement: const pgtools = require('pgtools');
953 - DatastoreTest.query('CREATE DATABASE '+ databaseName + ';', [], function (err, res) {
953 + DatastoreTest.query('CREATE DATABASE "'+ databaseName + '";', [], function (err, res) {
954 if (err == null) {
955 // Create the tables and indexes
956 DatastoreTest.end();
@@ -3420,8 +3420,8 @@ module.exports.CreateDB = function (parent, func) {
3420 // Check that we have access to pg_dump
3421 parent.config.settings.autobackup.pgdumppath = path.normalize(parent.config.settings.autobackup.pgdumppath ? parent.config.settings.autobackup.pgdumppath : 'pg_dump');
3422 let cmd = '"' + parent.config.settings.autobackup.pgdumppath + '"'
3423 - + ' --dbname=postgresql://' + parent.config.settings.postgres.user + ":" +parent.config.settings.postgres.password
3424 - + "@" + parent.config.settings.postgres.host + ":" + parent.config.settings.postgres.port + "/" + databaseName
3423 + + ' --dbname=postgresql://' + encodeURIComponent(parent.config.settings.postgres.user) + ":" + encodeURIComponent(parent.config.settings.postgres.password)
3424 + + "@" + parent.config.settings.postgres.host + ":" + parent.config.settings.postgres.port + "/" + encodeURIComponent(databaseName)
3425 + ' > ' + ((parent.platform == 'win32') ? '\"nul\"' : '\"/dev/null\"');
3426 const child_process = require('child_process');
3427 child_process.exec(cmd, { cwd: backupPath }, function(error, stdout, stdin) {
@@ -3614,11 +3614,11 @@ module.exports.CreateDB = function (parent, func) {
3614 });
3615 } else if (obj.databaseType == DB_POSTGRESQL) {
3616 // Perform a PostgresDump backup
3617 - const newBackupFile = databaseName + '-pgdump-' + fileSuffix + '.sql';
3617 + const newBackupFile = 'pgdump-' + fileSuffix + '.sql';
3618 obj.newDBDumpFile = path.join(backupPath, newBackupFile);
3619 let cmd = '"' + parent.config.settings.autobackup.pgdumppath + '"'
3620 - + ' --dbname=postgresql://' + parent.config.settings.postgres.user + ":" +parent.config.settings.postgres.password
3621 - + "@" + parent.config.settings.postgres.host + ":" + parent.config.settings.postgres.port + "/" + databaseName
3620 + + ' --dbname=postgresql://' + encodeURIComponent(parent.config.settings.postgres.user) + ":" + encodeURIComponent(parent.config.settings.postgres.password)
3621 + + "@" + parent.config.settings.postgres.host + ":" + parent.config.settings.postgres.port + "/" + encodeURIComponent(databaseName)
3622 + " --file=" + obj.newDBDumpFile;
3623 parent.debug('backup','Postgresqldump cmd: ' + cmd);
3624 const child_process = require('child_process');