From 4faf13222edead307109bf8c747200ea3fb617c0 Mon Sep 17 00:00:00 2001 From: "Feng, YunhuaX" Date: Thu, 1 Mar 2018 10:16:07 +0800 Subject: [PATCH] BaseTools: Fix eval parse string issue eval argument start with " or ', but it is unicode string, will encounter error: List = list(eval(Value)) # translate escape character File "", line 1 'j??=????????F?? ^ SyntaxError: EOL while scanning string literal Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Yunhua Feng Reviewed-by: Yonghong Zhu --- BaseTools/Source/Python/Common/Misc.py | 30 ++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Python/Common/Misc.py index a7e7797d04..af374d804d 100644 --- a/BaseTools/Source/Python/Common/Misc.py +++ b/BaseTools/Source/Python/Common/Misc.py @@ -1554,7 +1554,13 @@ def ParseFieldValue (Value): return Value, 16 if Value.startswith('L"') and Value.endswith('"'): # Unicode String - List = list(eval(Value[1:])) # translate escape character + # translate escape character + Value = Value[1:] + try: + Value = eval(Value) + except: + Value = Value[1:-1] + List = list(Value) List.reverse() Value = 0 for Char in List: @@ -1562,7 +1568,12 @@ def ParseFieldValue (Value): return Value, (len(List) + 1) * 2 if Value.startswith('"') and Value.endswith('"'): # ASCII String - List = list(eval(Value)) # translate escape character + # translate escape character + try: + Value = eval(Value) + except: + Value = Value[1:-1] + List = list(Value) List.reverse() Value = 0 for Char in List: @@ -1570,7 +1581,13 @@ def ParseFieldValue (Value): return Value, len(List) + 1 if Value.startswith("L'") and Value.endswith("'"): # Unicode Character Constant - List = list(eval(Value[1:])) # translate escape character + # translate escape character + Value = Value[1:] + try: + Value = eval(Value) + except: + Value = Value[1:-1] + List = list(Value) if len(List) == 0: raise BadExpression('Length %s is %s' % (Value, len(List))) List.reverse() @@ -1580,7 +1597,12 @@ def ParseFieldValue (Value): return Value, len(List) * 2 if Value.startswith("'") and Value.endswith("'"): # Character constant - List = list(eval(Value)) # translate escape character + # translate escape character + try: + Value = eval(Value) + except: + Value = Value[1:-1] + List = list(Value) if len(List) == 0: raise BadExpression('Length %s is %s' % (Value, len(List))) List.reverse() -- 2.39.2