summaryrefslogtreecommitdiff
path: root/json-glib/json-generator.c
diff options
context:
space:
mode:
Diffstat (limited to 'json-glib/json-generator.c')
-rw-r--r--json-glib/json-generator.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/json-glib/json-generator.c b/json-glib/json-generator.c
index 6b18bd9..6529ea6 100644
--- a/json-glib/json-generator.c
+++ b/json-glib/json-generator.c
@@ -257,7 +257,22 @@ dump_value (JsonGenerator *generator,
break;
case G_TYPE_STRING:
- g_string_append_printf (buffer, "\"%s\"", g_value_get_string (&value));
+ {
+ gchar *tmp;
+ gchar *exceptions = g_malloc (128);
+ gint chr, i;
+
+ /* non-ascii characters can't be escaped, otherwise utf-8
+ * chars will break */
+ for (i = 0, chr = 0x7f; chr <= 0xff; chr++, i++)
+ exceptions[i] = chr;
+
+ tmp = g_strescape (g_value_get_string (&value), exceptions);
+ g_free (exceptions);
+
+ g_string_append_printf (buffer, "\"%s\"", tmp);
+ g_free (tmp);
+ }
break;
case G_TYPE_DOUBLE: