]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools: Fix eval parse string issue
authorFeng, YunhuaX </o=Intel/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Recipients/cn=Feng, YunhuaX4e1>
Thu, 1 Mar 2018 02:16:07 +0000 (10:16 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Fri, 2 Mar 2018 02:05:03 +0000 (10:05 +0800)
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>
BaseTools/Source/Python/Common/Misc.py

index a7e7797d0499df0a70026c2f6674e83ae0a0054c..af374d804d86b8a01a5fee2ae38b0c2968169eaf 100644 (file)
@@ -1554,7 +1554,13 @@ def ParseFieldValue (Value):
         return Value, 16\r
     if Value.startswith('L"') and Value.endswith('"'):\r
         # Unicode String\r
-        List = list(eval(Value[1:]))  # translate escape character\r
+        # translate escape character\r
+        Value = Value[1:]\r
+        try:\r
+            Value = eval(Value)\r
+        except:\r
+            Value = Value[1:-1]\r
+        List = list(Value)\r
         List.reverse()\r
         Value = 0\r
         for Char in List:\r
@@ -1562,7 +1568,12 @@ def ParseFieldValue (Value):
         return Value, (len(List) + 1) * 2\r
     if Value.startswith('"') and Value.endswith('"'):\r
         # ASCII String\r
-        List = list(eval(Value))  # translate escape character\r
+        # translate escape character\r
+        try:\r
+            Value = eval(Value)\r
+        except:\r
+            Value = Value[1:-1]\r
+        List = list(Value)\r
         List.reverse()\r
         Value = 0\r
         for Char in List:\r
@@ -1570,7 +1581,13 @@ def ParseFieldValue (Value):
         return Value, len(List) + 1\r
     if Value.startswith("L'") and Value.endswith("'"):\r
         # Unicode Character Constant\r
-        List = list(eval(Value[1:])) # translate escape character\r
+        # translate escape character\r
+        Value = Value[1:]\r
+        try:\r
+            Value = eval(Value)\r
+        except:\r
+            Value = Value[1:-1]\r
+        List = list(Value)\r
         if len(List) == 0:\r
             raise BadExpression('Length %s is %s' % (Value, len(List)))\r
         List.reverse()\r
@@ -1580,7 +1597,12 @@ def ParseFieldValue (Value):
         return Value, len(List) * 2\r
     if Value.startswith("'") and Value.endswith("'"):\r
         # Character constant\r
-        List = list(eval(Value)) # translate escape character\r
+        # translate escape character\r
+        try:\r
+            Value = eval(Value)\r
+        except:\r
+            Value = Value[1:-1]\r
+        List = list(Value)\r
         if len(List) == 0:\r
             raise BadExpression('Length %s is %s' % (Value, len(List)))\r
         List.reverse()\r