]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Common/Expression.py
BaseTools: Add special handle for '\' use in Pcd Value
[mirror_edk2.git] / BaseTools / Source / Python / Common / Expression.py
index 05459b9c26ee7285b69f3fe391a4b4039ee0977b..a21ab5daa73ee95a462e413844431e412c3dc384 100644 (file)
@@ -22,6 +22,8 @@ import Common.EdkLogger as EdkLogger
 import copy\r
 from Common.DataType import *\r
 import sys\r
+from random import sample\r
+import string\r
 \r
 ERR_STRING_EXPR         = 'This operator cannot be used in string expression: [%s].'\r
 ERR_SNYTAX              = 'Syntax error, the rest of expression cannot be evaluated: [%s].'\r
@@ -55,6 +57,8 @@ PcdPattern = re.compile(r'[_a-zA-Z][0-9A-Za-z_]*\.[_a-zA-Z][0-9A-Za-z_]*$')
 #\r
 def SplitString(String):\r
     # There might be escaped quote: "abc\"def\\\"ghi", 'abc\'def\\\'ghi'\r
+    RanStr = ''.join(sample(string.ascii_letters + string.digits, 8))\r
+    String = String.replace('\\\\', RanStr).strip()\r
     RetList = []\r
     InSingleQuote = False\r
     InDoubleQuote = False\r
@@ -87,11 +91,16 @@ def SplitString(String):
         raise BadExpression(ERR_STRING_TOKEN % Item)\r
     if Item:\r
         RetList.append(Item)\r
+    for i, ch in enumerate(RetList):\r
+        if RanStr in ch:\r
+            RetList[i] = ch.replace(RanStr,'\\\\')\r
     return RetList\r
 \r
 def SplitPcdValueString(String):\r
     # There might be escaped comma in GUID() or DEVICE_PATH() or " "\r
     # or ' ' or L' ' or L" "\r
+    RanStr = ''.join(sample(string.ascii_letters + string.digits, 8))\r
+    String = String.replace('\\\\', RanStr).strip()\r
     RetList = []\r
     InParenthesis = 0\r
     InSingleQuote = False\r
@@ -124,6 +133,9 @@ def SplitPcdValueString(String):
         raise BadExpression(ERR_STRING_TOKEN % Item)\r
     if Item:\r
         RetList.append(Item)\r
+    for i, ch in enumerate(RetList):\r
+        if RanStr in ch:\r
+            RetList[i] = ch.replace(RanStr,'\\\\')\r
     return RetList\r
 \r
 def IsValidCName(Str):\r
@@ -390,7 +402,7 @@ class ValueExpression(BaseExpression):
             elif not Val:\r
                 Val = False\r
                 RealVal = '""'\r
-            elif not Val.startswith('L"') and not Val.startswith('{') and not Val.startswith("L'"):\r
+            elif not Val.startswith('L"') and not Val.startswith('{') and not Val.startswith("L'") and not Val.startswith("'"):\r
                 Val = True\r
                 RealVal = '"' + RealVal + '"'\r
 \r