Hi,

I worked on this bug since sunday evening, and it's really an annoying
one. We have an issue with objects' names containing double quotes when
doing a backup, whatever your OS is.

I found a fix, and I would usually commit it ASAP. But this time, I'm a
bit worried. I don't understand why the commandLineCleanOption()
function (in misc.c) is so complicated. There should be a reason.
Unfortunately, The fix I wrote deletes almost all of it.

If someone has an explanation of the function, I'm happy to hear it.

And if someone thinks my patch is just plain stupid, tell me before I
commit it :)

Thanks.


-- 
Guillaume
 http://www.postgresql.fr
 http://dalibo.com
diff --git a/pgadmin/frm/frmBackup.cpp b/pgadmin/frm/frmBackup.cpp
index 61c282d..f5a96a2 100644
--- a/pgadmin/frm/frmBackup.cpp
+++ b/pgadmin/frm/frmBackup.cpp
@@ -298,7 +298,7 @@ wxString frmBackup::getCmdPart1()
         cmd += wxT(" --host ") + server->GetName();
 
     cmd +=  wxT(" --port ") + NumToStr((long)server->GetPort())
-         +  wxT(" --username ") + commandLineCleanOption(qtIdent(server->GetUsername()));
+         +  wxT(" --username \"") + commandLineCleanOption(qtIdent(server->GetUsername())) + wxT("\"");
 
     if (object->GetConnection()->GetIsGreenplum())
         cmd += wxT(" --gp-syntax ");
@@ -401,15 +401,16 @@ wxString frmBackup::getCmdPart2()
                     // The syntax changed in 8.2 :-(
                     if (pgAppMinimumVersion(backupExecutable, 8, 2))
                     {
-                        tmpTables.Append(wxT(" --table ") + 
+                        tmpTables.Append(wxT(" --table \"") + 
                                     commandLineCleanOption(qtIdent(ctvObjects->GetItemText(schema)), true) +
                                     wxT(".") +
-                                    commandLineCleanOption(qtIdent(ctvObjects->GetItemText(table)), true));
+                                    commandLineCleanOption(qtIdent(ctvObjects->GetItemText(table)), true) +
+                                    wxT("\""));
                     }
                     else
                     {
-                        tmpTables.Append(wxT(" --table ") + commandLineCleanOption(qtIdent(ctvObjects->GetItemText(table)), true));
-                        tmpTables.Append(wxT(" --schema ") + commandLineCleanOption(qtIdent(ctvObjects->GetItemText(schema)), true));
+                        tmpTables.Append(wxT(" --table \"") + commandLineCleanOption(qtIdent(ctvObjects->GetItemText(table)), true) + wxT("\""));
+                        tmpTables.Append(wxT(" --schema \"") + commandLineCleanOption(qtIdent(ctvObjects->GetItemText(schema)), true) + wxT("\""));
                     }
                 }
                 else
@@ -426,7 +427,7 @@ wxString frmBackup::getCmdPart2()
             }
             else
             {
-                cmdSchemas.Append(wxT(" --schema ") + commandLineCleanOption(qtIdent(ctvObjects->GetItemText(schema)), true));
+                cmdSchemas.Append(wxT(" --schema \"") + commandLineCleanOption(qtIdent(ctvObjects->GetItemText(schema)), true) + wxT("\""));
             }
         }
         else
diff --git a/pgadmin/frm/frmBackupGlobals.cpp b/pgadmin/frm/frmBackupGlobals.cpp
index 9c16085..4b85e4d 100644
--- a/pgadmin/frm/frmBackupGlobals.cpp
+++ b/pgadmin/frm/frmBackupGlobals.cpp
@@ -162,7 +162,7 @@ wxString frmBackupGlobals::getCmdPart1()
         cmd += wxT(" --host ") + server->GetName();
 
     cmd +=  wxT(" --port ") + NumToStr((long)server->GetPort())
-         +  wxT(" --username ") + commandLineCleanOption(qtIdent(server->GetUsername()));
+         +  wxT(" --username \"") + commandLineCleanOption(qtIdent(server->GetUsername())) + wxT("\"");
     return cmd;
 }
 
diff --git a/pgadmin/frm/frmBackupServer.cpp b/pgadmin/frm/frmBackupServer.cpp
index d90c81f..b8a139b 100644
--- a/pgadmin/frm/frmBackupServer.cpp
+++ b/pgadmin/frm/frmBackupServer.cpp
@@ -147,7 +147,7 @@ wxString frmBackupServer::getCmdPart1()
         cmd += wxT(" --host ") + server->GetName();
 
     cmd +=  wxT(" --port ") + NumToStr((long)server->GetPort())
-         +  wxT(" --username ") + commandLineCleanOption(qtIdent(server->GetUsername()));
+         +  wxT(" --username \"") + commandLineCleanOption(qtIdent(server->GetUsername())) + wxT("\"");
     return cmd;
 }
 
diff --git a/pgadmin/utils/misc.cpp b/pgadmin/utils/misc.cpp
index 1b59a83..a4903fb 100644
--- a/pgadmin/utils/misc.cpp
+++ b/pgadmin/utils/misc.cpp
@@ -1315,26 +1315,8 @@ wxString commandLineCleanOption(const wxString &option, bool schemaObject)
 {
     wxString tmp = option;
 
-    // Only double-quoted string needs to be formatted
-    if (option.StartsWith(wxT("\"")) && option.EndsWith(wxT("\"")))
-    {
-        tmp = option.AfterFirst((wxChar)'"').BeforeLast((wxChar)'"');
-
-        // Replace single splash to double-splash
-        tmp.Replace(wxT("\\"), wxT("\\\\"));
-
-        // Replace double-quote with slash & double-quote
-        tmp.Replace(wxT("\""), wxT("\\\""));
-
-        if (!schemaObject)
-            // Replace double (slash & double-quote) combination to single (slash & double-quote) combination
-            tmp.Replace(wxT("\\\"\\\""), wxT("\\\""));
-        else
-            // Replace double (slash & double-quote) combination to triple (slash & double-quote) combination
-            tmp.Replace(wxT("\\\"\\\""), wxT("\\\"\\\"\\\""));
-
-        tmp = wxT("\"") + tmp + wxT("\"");
-    }
+	// Replace double-quote with slash & double-quote
+    tmp.Replace(wxT("\""), wxT("\\\""));
 
     return tmp;
 }
-- 
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers

Reply via email to