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
This commit is contained in:
Matthias Clasen
2007-08-09 02:06:04 +00:00
committed by Matthias Clasen
parent c4b9053e16
commit 28f781501e
3 changed files with 61 additions and 4 deletions

View File

@@ -26,6 +26,24 @@ test (const gchar *original,
g_free (result);
}
static void
test_unichar (gunichar c,
gboolean entity)
{
gint len;
gchar outbuf[7], expected[12];
len = g_unichar_to_utf8 (c, outbuf);
outbuf[len] = 0;
if (entity)
g_snprintf (expected, 12, "&#x%x;", c);
else
strcpy (expected, outbuf);
test (outbuf, expected);
}
static void
test_format (const gchar *format,
const gchar *expected,
@@ -67,6 +85,25 @@ int main (int argc, char **argv)
test ("A&&", "A&amp;&amp;");
test ("A&&A", "A&amp;&amp;A");
test ("A&A&A", "A&amp;A&amp;A");
test ("A&#23;A", "A&amp;#23;A");
test ("A&#xa;A", "A&amp;#xa;A");
test_unichar (0x1, TRUE);
test_unichar (0x8, TRUE);
test_unichar (0x9, FALSE);
test_unichar (0xa, FALSE);
test_unichar (0xb, TRUE);
test_unichar (0xc, TRUE);
test_unichar (0xd, FALSE);
test_unichar (0xe, TRUE);
test_unichar (0x1f, TRUE);
test_unichar (0x20, FALSE);
test_unichar (0x7e, FALSE);
test_unichar (0x7f, TRUE);
test_unichar (0x84, TRUE);
test_unichar (0x85, FALSE);
test_unichar (0x86, TRUE);
test_unichar (0x9f, TRUE);
test_unichar (0xa0, FALSE);
/* Tests for g_markup_printf_escaped() */
test_format ("A", "A");