From: zhijufan <[email protected]> Case: gEfiOzmosisPkgTokenSpaceGuid.PcdBootLogFolderPath|L"\\Logs\\"|VOID*|12
Fixes: https://bugzilla.tianocore.org/show_bug.cgi?id=1287 Cc: Liming Gao <[email protected]> Cc: Yonghong Zhu <[email protected]> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Zhiju.Fan <[email protected]> --- BaseTools/Source/Python/Common/Expression.py | 13 ++++++++++++- BaseTools/Source/Python/Common/Misc.py | 9 ++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/BaseTools/Source/Python/Common/Expression.py b/BaseTools/Source/Python/Common/Expression.py index 05459b9..6eec0de 100644 --- a/BaseTools/Source/Python/Common/Expression.py +++ b/BaseTools/Source/Python/Common/Expression.py @@ -20,10 +20,11 @@ from CommonDataClass.Exceptions import WrnExpression from .Misc import GuidStringToGuidStructureString, ParseFieldValue import Common.EdkLogger as EdkLogger import copy from Common.DataType import * import sys +import random, 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].' ERR_MATCH = 'No matching right parenthesis.' ERR_STRING_TOKEN = 'Bad string token: [%s].' @@ -53,10 +54,12 @@ PcdPattern = re.compile(r'[_a-zA-Z][0-9A-Za-z_]*\.[_a-zA-Z][0-9A-Za-z_]*$') # Split string to list according double quote # For example: abc"de\"f"ghi"jkl"mn will be: ['abc', '"de\"f"', 'ghi', '"jkl"', 'mn'] # def SplitString(String): # There might be escaped quote: "abc\"def\\\"ghi", 'abc\'def\\\'ghi' + RanStr = ''.join(random.sample(string.ascii_letters + string.digits, 8)) + String = String.replace('\\\\', RanStr).strip() RetList = [] InSingleQuote = False InDoubleQuote = False Item = '' for i, ch in enumerate(String): @@ -85,15 +88,20 @@ def SplitString(String): Item += String[i] if InSingleQuote or InDoubleQuote: 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(random.sample(string.ascii_letters + string.digits, 8)) + String = String.replace('\\\\', RanStr).strip() RetList = [] InParenthesis = 0 InSingleQuote = False InDoubleQuote = False Item = '' @@ -122,10 +130,13 @@ def SplitPcdValueString(String): Item += String[i] if InSingleQuote or InDoubleQuote or InParenthesis: 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): return True if __ValidString.match(Str) else False @@ -388,11 +399,11 @@ class ValueExpression(BaseExpression): if Val == 'L""': Val = False 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 + '"' # The expression has been parsed, but the end of expression is not reached # It means the rest does not comply EBNF of <Expression> diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Python/Common/Misc.py index b32b7cd..b27268a 100644 --- a/BaseTools/Source/Python/Common/Misc.py +++ b/BaseTools/Source/Python/Common/Misc.py @@ -15,11 +15,11 @@ # Import Modules # from __future__ import absolute_import import Common.LongFilePathOs as os import sys -import string +import random, string import threading import time import re import pickle import array @@ -1234,11 +1234,12 @@ def IsFieldValueAnArray (Value): if Value[0] == "'" and Value[-1] == "'" and len(list(Value[1:-1])) > 1: return True return False def AnalyzePcdExpression(Setting): - Setting = Setting.strip() + RanStr = ''.join(random.sample(string.ascii_letters + string.digits, 8)) + Setting = Setting.replace('\\\\', RanStr).strip() # There might be escaped quote in a string: \", \\\" , \', \\\' Data = Setting # There might be '|' in string and in ( ... | ... ), replace it with '-' NewStr = '' InSingleQuoteStr = False @@ -1267,11 +1268,13 @@ def AnalyzePcdExpression(Setting): if Pos < 0: FieldList.append(Setting[StartPos:].strip()) break FieldList.append(Setting[StartPos:Pos].strip()) StartPos = Pos + 1 - + for i, ch in enumerate(FieldList): + if RanStr in ch: + FieldList[i] = ch.replace(RanStr,'\\\\') return FieldList def ParseDevPathValue (Value): if '\\' in Value: Value.replace('\\', '/').replace(' ', '') -- 2.6.1.windows.1 _______________________________________________ edk2-devel mailing list [email protected] https://lists.01.org/mailman/listinfo/edk2-devel

