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.
*/
static char *
escape(const gchar *text) {
size_t len;
size_t i, j;
int count = 0;
escape(const gchar *text) {
gchar *escaped;
gchar **split;
gchar *result;
len = strlen(text);
for (i = 0; i < len; i++) {
if (text[i] == '\'') {
count++;
}
}
if (count == 0) {
return g_strdup(text);
}
/* Make sure all newlines, tabs, etc. are escaped. */
escaped = g_strescape (text, NULL);
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++) {
if (text[i] == '\'') {
escaped[j] = '\\';
j++;
}
escaped[j] = text[i];
j++;
}
g_free (escaped);
g_strfreev (split);
return escaped;
return result;
}

Loading…
Cancel
Save