From 56f40a9c7646ef714c4b7e65fc87724fb3efb135 Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Sun, 15 Mar 2015 19:19:57 +0100 Subject: [PATCH] Ensure the script is Unicode before parsing. --- lslopt/lslparse.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lslopt/lslparse.py b/lslopt/lslparse.py index 34b4d0a..f427cf0 100644 --- a/lslopt/lslparse.py +++ b/lslopt/lslparse.py @@ -2232,7 +2232,15 @@ list lazy_list_set(list L, integer i, list v) This function also builds the temporary globals table. """ + self.script = script + if type(script) is not unicode: + try: + self.script = script.decode('utf8') + except UnicodeDecodeError as E: + self.errorpos = E.start + raise EParse(self, 'Invalid UTF-8 in script') + self.length = len(script) # Extended expressions in globals (needs support from the optimizer to work)