From e8201d6956efbfa8139496ead80c7bfcd3fdc361 Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Tue, 13 Dec 2016 14:26:48 +0100 Subject: [PATCH] Err when invalid UTF-8 should have been generated in LSO mode. LSO strings are byte arrays, but our strings are made for Mono which uses Unicode, and invalid UTF-8 sequences can't be stored in Unicode without using a custom representation. One possible representation is to only use the codepoints 0-255 in the Unicode string, to avoid supporting multiple types for strings. Something to study in future. --- lslopt/lslbasefuncs.py | 6 ++++++ lslopt/lslcommon.py | 3 +++ 2 files changed, 9 insertions(+) diff --git a/lslopt/lslbasefuncs.py b/lslopt/lslbasefuncs.py index f32f3fa..8519287 100644 --- a/lslopt/lslbasefuncs.py +++ b/lslopt/lslbasefuncs.py @@ -475,6 +475,8 @@ def InternalUTF8toString(s): # NOTE: Without the above line, the following one hits a bug in # python-coverage. It IS executed but not detected. continue + if LSO: + raise ELSONotSupported("Byte strings not supported") ret += u'?' * len(partialchar) partialchar = b'' # fall through to process current character @@ -482,11 +484,15 @@ def InternalUTF8toString(s): partialchar = c pending = 1 if o < 0xE0 else 2 if o < 0xF0 else 3 elif o >= 0x80: + if LSO: + raise ELSONotSupported("Byte strings not supported") ret += u'?' else: ret += c.decode('utf8') if partialchar: + if LSO: + raise ELSONotSupported("Byte strings not supported") ret += u'?' * len(partialchar) return zstr(ret) diff --git a/lslopt/lslcommon.py b/lslopt/lslcommon.py index a4e351f..5bd285b 100644 --- a/lslopt/lslcommon.py +++ b/lslopt/lslcommon.py @@ -30,6 +30,9 @@ class Quaternion(tuple): def __repr__(self): return 'Quaternion(' + super(Quaternion, self).__repr__() + ')' +class ELSONotSupported(Exception): + pass + # Recognized: 3763, 6466, 6495 Bugs = set([6495])