From c7568cfdec8ababa4d73eddb7bed057404a6a009 Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Tue, 5 Jan 2021 13:30:26 +0100 Subject: [PATCH] pyuno: uno.Char is UTF-16 code unit, not UCS-4 Check for that in ctor. Change-Id: Ia69b3d87ac4ccb5b6cc13169d7022c04607c609f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108803 Tested-by: Jenkins Reviewed-by: Michael Stahl --- pyuno/source/module/uno.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pyuno/source/module/uno.py b/pyuno/source/module/uno.py index c4ca808feaa0..5fa7b135736d 100644 --- a/pyuno/source/module/uno.py +++ b/pyuno/source/module/uno.py @@ -225,9 +225,9 @@ class Char: Use an instance of this class to explicitly pass a char to UNO. - For Python 2, this class only works with unicode objects. Creating - a Char instance with a normal str object or comparing a Char instance - to a normal str object will raise an AssertionError. + For Python 3, this class only works with unicode (str) objects. Creating + a Char instance with a bytes object or comparing a Char instance + to a bytes object will raise an AssertionError. :param value: A Unicode string with length 1 """ @@ -236,6 +236,7 @@ class Char: assert isinstance(value, str), "Expected str object, got %s instead." % type(value) assert len(value) == 1, "Char value must have length of 1." + assert ord(value[0]) <= 0xFFFF, "Char value must be UTF-16 code unit" self.value = value