Browse Source

Fix major bug in escape function; also need to worry about newlines, etc. Replace with g_str functions.

(cherry picked from commit 1ea83d1)
sisyphus
Scott Balneaves 9 years ago committed by Dustin Falgout
parent
commit
4effcd2cf5
  1. 39
      src/lightdm-webkit2-greeter-ext.c

39
src/lightdm-webkit2-greeter-ext.c

@ -170,39 +170,24 @@ arg_to_string(JSContextRef context, JSValueRef arg, JSValueRef *exception) {
* quote characters escaped. * quote characters escaped.
*/ */
static char * static char *
escape(const gchar *text) { escape(const gchar *text) {
size_t len;
size_t i, j;
int count = 0;
gchar *escaped; gchar *escaped;
gchar **split;
gchar *result;
len = strlen(text); /* Make sure all newlines, tabs, etc. are escaped. */
escaped = g_strescape (text, NULL);
for (i = 0; i < len; i++) {
if (text[i] == '\'') {
count++;
}
}
if (count == 0) {
return g_strdup(text);
}
escaped = g_malloc(len + count + 1); /* Split the string up on the single quote character (') */
split = g_strsplit (escaped, "'", -1);
j = 0; /* Rejoin, substituting the escaped single quote for the separator. */
result = g_strjoinv ("\\'", split);
for (i = 0; i <= len; i++) { g_free (escaped);
if (text[i] == '\'') { g_strfreev (split);
escaped[j] = '\\';
j++;
}
escaped[j] = text[i];
j++;
}
return escaped; return result;
} }

Loading…
Cancel
Save