GNOME Bugzilla – Bug 464145
g_markup_escape_text Produces Invalid XML
Last modified: 2007-08-09 02:07:48 UTC
Please describe the problem: g_markup_escape_text does not properly escape characters not allowed in XML using entities. Steps to reproduce: 1. Create markuptest.c with the following content: #include <stdio.h> #include <glib.h> main() { char input[1]; input[0] = 0x0f; gchar *out = g_markup_escape_text(input, 1); return printf("<tag>%s</tag>",out); } 2. Compile & link it 3. Install libxml2 (if not done already) 4. Run: ./markuptest | xmllint - Actual results: -:1: parser error : PCDATA invalid Char value 15 <tag></tag> ^ Expected results: Output of something like <tag></tag> Does this happen every time? yes Other information: It's probably necessary to implement the list described in http://www.w3.org/TR/REC-xml/#NT-BaseChar into this function and escape all other characters.
I'd much rather follow http://www.w3.org/TR/2006/REC-xml11-20060816/#charsets which has a much simpler table.
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.