summaryrefslogtreecommitdiffstats
path: root/BaseTools/Source/Python/Common/Expression.py
diff options
context:
space:
mode:
authorzhijufan <zhijux.fan@intel.com>2018-10-17 13:57:01 +0800
committerYonghong Zhu <yonghong.zhu@intel.com>2018-11-01 10:27:13 +0800
commitd3d97b378fe4d0bfbcbdb296d06bcf1d09165480 (patch)
treeaf7e1c1944a760e37f91425dd59303f46c2ee6f4 /BaseTools/Source/Python/Common/Expression.py
parent5b9639e697350c9e18e98ddb0119e8598b004a8f (diff)
downloadedk2-d3d97b378fe4d0bfbcbdb296d06bcf1d09165480.tar.gz
edk2-d3d97b378fe4d0bfbcbdb296d06bcf1d09165480.tar.bz2
edk2-d3d97b378fe4d0bfbcbdb296d06bcf1d09165480.zip
BaseTools: Add special handle for '\' use in Pcd Value
V2: Follow PEP8 to not multiples import on one line Case: gEfiOzmosisPkgTokenSpaceGuid.PcdBootLogFolderPath|L"\\Logs\\"|VOID*|12 Fixes: https://bugzilla.tianocore.org/show_bug.cgi?id=1287 Cc: Liming Gao <liming.gao@intel.com> Cc: Yonghong Zhu <yonghong.zhu@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Zhiju.Fan <zhijux.fan@intel.com> Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
Diffstat (limited to 'BaseTools/Source/Python/Common/Expression.py')
-rw-r--r--BaseTools/Source/Python/Common/Expression.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/BaseTools/Source/Python/Common/Expression.py b/BaseTools/Source/Python/Common/Expression.py
index 05459b9c26..a21ab5daa7 100644
--- a/BaseTools/Source/Python/Common/Expression.py
+++ b/BaseTools/Source/Python/Common/Expression.py
@@ -22,6 +22,8 @@ import Common.EdkLogger as EdkLogger
import copy
from Common.DataType import *
import sys
+from random import sample
+import string
ERR_STRING_EXPR = 'This operator cannot be used in string expression: [%s].'
ERR_SNYTAX = 'Syntax error, the rest of expression cannot be evaluated: [%s].'
@@ -55,6 +57,8 @@ PcdPattern = re.compile(r'[_a-zA-Z][0-9A-Za-z_]*\.[_a-zA-Z][0-9A-Za-z_]*$')
#
def SplitString(String):
# There might be escaped quote: "abc\"def\\\"ghi", 'abc\'def\\\'ghi'
+ RanStr = ''.join(sample(string.ascii_letters + string.digits, 8))
+ String = String.replace('\\\\', RanStr).strip()
RetList = []
InSingleQuote = False
InDoubleQuote = False
@@ -87,11 +91,16 @@ def SplitString(String):
raise BadExpression(ERR_STRING_TOKEN % Item)
if Item:
RetList.append(Item)
+ for i, ch in enumerate(RetList):
+ if RanStr in ch:
+ RetList[i] = ch.replace(RanStr,'\\\\')
return RetList
def SplitPcdValueString(String):
# There might be escaped comma in GUID() or DEVICE_PATH() or " "
# or ' ' or L' ' or L" "
+ RanStr = ''.join(sample(string.ascii_letters + string.digits, 8))
+ String = String.replace('\\\\', RanStr).strip()
RetList = []
InParenthesis = 0
InSingleQuote = False
@@ -124,6 +133,9 @@ def SplitPcdValueString(String):
raise BadExpression(ERR_STRING_TOKEN % Item)
if Item:
RetList.append(Item)
+ for i, ch in enumerate(RetList):
+ if RanStr in ch:
+ RetList[i] = ch.replace(RanStr,'\\\\')
return RetList
def IsValidCName(Str):
@@ -390,7 +402,7 @@ class ValueExpression(BaseExpression):
elif not Val:
Val = False
RealVal = '""'
- elif not Val.startswith('L"') and not Val.startswith('{') and not Val.startswith("L'"):
+ elif not Val.startswith('L"') and not Val.startswith('{') and not Val.startswith("L'") and not Val.startswith("'"):
Val = True
RealVal = '"' + RealVal + '"'