From 479610ff30349896d7d4287ab2fdfb6a5501c0b5 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Mon, 23 Jul 2018 18:21:15 +0100 Subject: [PATCH] better handling of ASCII control chars in xml represent ASCII control chars as their unicode glyphs in XML see http://www.shacknews.com/chatty?id=37738911#item_37738911 --- libvips/iofuncs/vips.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/libvips/iofuncs/vips.c b/libvips/iofuncs/vips.c index f4dde475..21c5d951 100644 --- a/libvips/iofuncs/vips.c +++ b/libvips/iofuncs/vips.c @@ -782,15 +782,14 @@ dbuf_write_amp( VipsDbuf *dbuf, const char *str ) for( p = str; *p; p++ ) if( *p < 32 ) /* You'd think we could output "%x;", but xml - * 1.0 parsers barf on that. Perhaps we should use '?', - * but this is frankly better. + * 1.0 parsers barf on that. xml 1.1 allows this, but + * there are almost no parsers. * - * xml 1.1 allows this, but expat does not support - * it. - * - * vips_dbuf_writef( dbuf, "&#x%02x;", *p ); + * U+2400 onwards are unicode glyphs for the ASCII + * control characters, so we can use them -- thanks + * electroly. */ - vips_dbuf_write( dbuf, (guchar *) "🐄", 9 ); + vips_dbuf_writef( dbuf, "&#x%04x;", 0x2400 + *p ); else if( *p == '<' ) vips_dbuf_write( dbuf, (guchar *) "<", 4 ); else if( *p == '>' )