summaryrefslogtreecommitdiff
path: root/glib
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2007-08-09 02:06:04 +0000
committerMatthias Clasen <matthiasc@src.gnome.org>2007-08-09 02:06:04 +0000
commit28f781501e4c9a7f83b459d83f14c396fce0c981 (patch)
treee40d952a9f01852c97b3c5962e00dfe9ad07da8b /glib
parentc4b9053e16ba1ed9f9e448792cc395a29f9f8fb2 (diff)
downloadglib-28f781501e4c9a7f83b459d83f14c396fce0c981.tar.gz
Handle restricted characters by converting them to numeric character
2007-08-08 Matthias Clasen <mclasen@redhat.com> * glib/gmarkup.c (append_escaped_text): Handle restricted characters by converting them to numeric character entities. (#464145, Andreas Monitzer) * tests/markup-escape-test.c: Add tests for restricted characters and numeric character entities. svn path=/trunk/; revision=5684
Diffstat (limited to 'glib')
-rw-r--r--glib/gmarkup.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/glib/gmarkup.c b/glib/gmarkup.c
index e0179f394..4c941590f 100644
--- a/glib/gmarkup.c
+++ b/glib/gmarkup.c
@@ -955,7 +955,7 @@ g_markup_parse_context_parse (GMarkupParseContext *context,
set_error (context,
error,
G_MARKUP_ERROR_BAD_UTF8,
- _("Invalid UTF-8 encoded text"));
+ _("Invalid UTF-8 encoded text - overlong sequence"));
}
goto finished;
@@ -983,7 +983,7 @@ g_markup_parse_context_parse (GMarkupParseContext *context,
set_error (context,
error,
G_MARKUP_ERROR_BAD_UTF8,
- _("Invalid UTF-8 encoded text"));
+ _("Invalid UTF-8 encoded text - not a start char"));
goto finished;
}
@@ -1019,7 +1019,9 @@ g_markup_parse_context_parse (GMarkupParseContext *context,
set_error (context,
error,
G_MARKUP_ERROR_BAD_UTF8,
- _("Invalid UTF-8 encoded text"));
+ _("Invalid UTF-8 encoded text - not valid '%s'"),
+ g_strndup (context->current_text,
+ context->current_text_len));
goto finished;
}
@@ -1900,6 +1902,7 @@ append_escaped_text (GString *str,
{
const gchar *p;
const gchar *end;
+ gunichar c;
p = text;
end = text + length;
@@ -1932,7 +1935,15 @@ append_escaped_text (GString *str,
break;
default:
- g_string_append_len (str, p, next - p);
+ c = g_utf8_get_char (p);
+ if ((0x1 <= c && c <= 0x8) ||
+ (0xb <= c && c <= 0xc) ||
+ (0xe <= c && c <= 0x1f) ||
+ (0x7f <= c && c <= 0x84) ||
+ (0x86 <= c && c <= 0x9f))
+ g_string_append_printf (str, "&#x%x;", c);
+ else
+ g_string_append_len (str, p, next - p);
break;
}