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 "<string>", line 1
'j??=????????F??
^
SyntaxError: EOL while scanning string literal
Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yunhua Feng <yunhuax.feng@intel.com>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
(cherry picked from commit 4faf13222e
)
This commit is contained in:
committed by
Liming Gao
parent
194ae4278a
commit
43473e3dcd
@ -1554,7 +1554,13 @@ def ParseFieldValue (Value):
|
|||||||
return Value, 16
|
return Value, 16
|
||||||
if Value.startswith('L"') and Value.endswith('"'):
|
if Value.startswith('L"') and Value.endswith('"'):
|
||||||
# Unicode String
|
# 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()
|
List.reverse()
|
||||||
Value = 0
|
Value = 0
|
||||||
for Char in List:
|
for Char in List:
|
||||||
@ -1562,7 +1568,12 @@ def ParseFieldValue (Value):
|
|||||||
return Value, (len(List) + 1) * 2
|
return Value, (len(List) + 1) * 2
|
||||||
if Value.startswith('"') and Value.endswith('"'):
|
if Value.startswith('"') and Value.endswith('"'):
|
||||||
# ASCII String
|
# 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()
|
List.reverse()
|
||||||
Value = 0
|
Value = 0
|
||||||
for Char in List:
|
for Char in List:
|
||||||
@ -1570,7 +1581,13 @@ def ParseFieldValue (Value):
|
|||||||
return Value, len(List) + 1
|
return Value, len(List) + 1
|
||||||
if Value.startswith("L'") and Value.endswith("'"):
|
if Value.startswith("L'") and Value.endswith("'"):
|
||||||
# Unicode Character Constant
|
# 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:
|
if len(List) == 0:
|
||||||
raise BadExpression('Length %s is %s' % (Value, len(List)))
|
raise BadExpression('Length %s is %s' % (Value, len(List)))
|
||||||
List.reverse()
|
List.reverse()
|
||||||
@ -1580,7 +1597,12 @@ def ParseFieldValue (Value):
|
|||||||
return Value, len(List) * 2
|
return Value, len(List) * 2
|
||||||
if Value.startswith("'") and Value.endswith("'"):
|
if Value.startswith("'") and Value.endswith("'"):
|
||||||
# Character constant
|
# 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:
|
if len(List) == 0:
|
||||||
raise BadExpression('Length %s is %s' % (Value, len(List)))
|
raise BadExpression('Length %s is %s' % (Value, len(List)))
|
||||||
List.reverse()
|
List.reverse()
|
||||||
|
Reference in New Issue
Block a user