|
|
@ -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; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|