[pango/wip/smcv/json-unsigned-char] serializer: Serialize non-ASCII correctly if char is unsigned




commit 18235a64c08b6dac3be5d368f3baaee285cabc3d
Author: Simon McVittie <smcv debian org>
Date:   Tue Jan 4 19:47:42 2022 +0000

    serializer: Serialize non-ASCII correctly if char is unsigned
    
    If char is unsigned, the first byte of a non-trivial UTF-8 sequence will
    be 0x80 or higher, instead of being negative. In this case we need to
    process it as UTF-8, instead of printing only the first byte and then
    skipping to the next UTF-8 character.
    
    char is usually signed on x86 and some other architectures, but not on
    the ARM or PowerPC families, among others.
    
    Resolves: https://gitlab.gnome.org/GNOME/pango/-/issues/652
    Signed-off-by: Simon McVittie <smcv debian org>

 pango/json/gtkjsonprinter.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
---
diff --git a/pango/json/gtkjsonprinter.c b/pango/json/gtkjsonprinter.c
index f2f1e273..e9ca03a3 100644
--- a/pango/json/gtkjsonprinter.c
+++ b/pango/json/gtkjsonprinter.c
@@ -226,7 +226,7 @@ gtk_json_printer_escape_string (GtkJsonPrinter *self,
             g_string_append (string, "\\t");
             break;
           default:
-            if ((int) *str < 0x20)
+            if ((int) *str < 0x20 || (int) *str >= 0x80)
               {
                 if ((guint) *str < 0x20 || gtk_json_printer_has_flag (self, GTK_JSON_PRINTER_ASCII))
                   g_string_append_printf (string, "\\u%04x", g_utf8_get_char (str));


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]