Escape double-quotes in strings passed to an event notification script

The string in question will be generated internally by repmgr as a simple
one-line string with no control characters etc., so all that needs to be
escaped at the moment are any double quotes.
This commit is contained in:
Ian Barwick
2017-11-16 10:36:48 +09:00
parent a9a17f206e
commit b8b991398a
5 changed files with 38 additions and 5 deletions

View File

@@ -369,6 +369,31 @@ escape_string(PGconn *conn, const char *string)
}
/*
* simple function to escape double quotes only
*/
void
escape_double_quotes(char *string, PQExpBufferData *out)
{
char *ptr;
for (ptr = string; *ptr; ptr++)
{
if (*ptr == '"')
{
if ( (ptr == string) || (ptr > string && *(ptr - 1) != '\\'))
{
appendPQExpBufferChar(out, '\\');
}
}
appendPQExpBufferChar(out, *ptr);
}
return;
}
char *
string_skip_prefix(const char *prefix, char *string)
{