mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-20 15:48:54 +02:00
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:
committed by
Matthias Clasen
parent
c4b9053e16
commit
28f781501e
@@ -1,3 +1,12 @@
|
|||||||
|
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.
|
||||||
|
|
||||||
2007-08-08 Matthias Clasen <mclasen@redhat.com>
|
2007-08-08 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
* glib/glib.symbols:
|
* glib/glib.symbols:
|
||||||
|
@@ -955,7 +955,7 @@ g_markup_parse_context_parse (GMarkupParseContext *context,
|
|||||||
set_error (context,
|
set_error (context,
|
||||||
error,
|
error,
|
||||||
G_MARKUP_ERROR_BAD_UTF8,
|
G_MARKUP_ERROR_BAD_UTF8,
|
||||||
_("Invalid UTF-8 encoded text"));
|
_("Invalid UTF-8 encoded text - overlong sequence"));
|
||||||
}
|
}
|
||||||
|
|
||||||
goto finished;
|
goto finished;
|
||||||
@@ -983,7 +983,7 @@ g_markup_parse_context_parse (GMarkupParseContext *context,
|
|||||||
set_error (context,
|
set_error (context,
|
||||||
error,
|
error,
|
||||||
G_MARKUP_ERROR_BAD_UTF8,
|
G_MARKUP_ERROR_BAD_UTF8,
|
||||||
_("Invalid UTF-8 encoded text"));
|
_("Invalid UTF-8 encoded text - not a start char"));
|
||||||
goto finished;
|
goto finished;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1019,7 +1019,9 @@ g_markup_parse_context_parse (GMarkupParseContext *context,
|
|||||||
set_error (context,
|
set_error (context,
|
||||||
error,
|
error,
|
||||||
G_MARKUP_ERROR_BAD_UTF8,
|
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;
|
goto finished;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1900,6 +1902,7 @@ append_escaped_text (GString *str,
|
|||||||
{
|
{
|
||||||
const gchar *p;
|
const gchar *p;
|
||||||
const gchar *end;
|
const gchar *end;
|
||||||
|
gunichar c;
|
||||||
|
|
||||||
p = text;
|
p = text;
|
||||||
end = text + length;
|
end = text + length;
|
||||||
@@ -1932,6 +1935,14 @@ append_escaped_text (GString *str,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
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);
|
g_string_append_len (str, p, next - p);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -26,6 +26,24 @@ test (const gchar *original,
|
|||||||
g_free (result);
|
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
|
static void
|
||||||
test_format (const gchar *format,
|
test_format (const gchar *format,
|
||||||
const gchar *expected,
|
const gchar *expected,
|
||||||
@@ -67,6 +85,25 @@ int main (int argc, char **argv)
|
|||||||
test ("A&&", "A&&");
|
test ("A&&", "A&&");
|
||||||
test ("A&&A", "A&&A");
|
test ("A&&A", "A&&A");
|
||||||
test ("A&A&A", "A&A&A");
|
test ("A&A&A", "A&A&A");
|
||||||
|
test ("AA", "A&#23;A");
|
||||||
|
test ("A
A", "A&#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() */
|
/* Tests for g_markup_printf_escaped() */
|
||||||
test_format ("A", "A");
|
test_format ("A", "A");
|
||||||
|
Reference in New Issue
Block a user