From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.31; helo=mga06.intel.com; envelope-from=jaben.carsey@intel.com; receiver=edk2-devel@lists.01.org Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 7BAAE2116DA08 for ; Tue, 30 Oct 2018 07:21:51 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Oct 2018 07:21:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,444,1534834800"; d="scan'208";a="103788896" Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by fmsmga001.fm.intel.com with ESMTP; 30 Oct 2018 07:21:50 -0700 Received: from fmsmsx103.amr.corp.intel.com ([169.254.2.186]) by FMSMSX108.amr.corp.intel.com ([169.254.9.157]) with mapi id 14.03.0415.000; Tue, 30 Oct 2018 07:21:50 -0700 From: "Carsey, Jaben" To: "Zhu, Yonghong" , "edk2-devel@lists.01.org" CC: "Gao, Liming" Thread-Topic: [edk2] [Patch] BaseTools: Add special handle for '\' use in Pcd Value Thread-Index: AQHUcFRf//NnAQuCtUuIOayYN5zc6aU31kjQ Date: Tue, 30 Oct 2018 14:21:48 +0000 Message-ID: References: <1540906064-15080-1-git-send-email-yonghong.zhu@intel.com> In-Reply-To: <1540906064-15080-1-git-send-email-yonghong.zhu@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiMzA4YzJlZjAtNWQ3NS00YTAzLThiNTUtYzBmYWI1NzhmNTdmIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiZmNcL1B4a1R5VTVlc2pOU3R5bE5jRDFrNFJTOEFGXC9LUklKUDRFMmpGWVZOK0NvWVdWWmF0ZjRGMEVZdWdzSUtJIn0= x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.0.400.15 dlp-reaction: no-action x-originating-ip: [10.1.200.108] MIME-Version: 1.0 Subject: Re: [Patch] BaseTools: Add special handle for '\' use in Pcd Value X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 Oct 2018 14:21:51 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Please separate includes to each on their own line. PEP8 says no to multipl= es on one line. Not:=20 include random, string But instead: include string include random Also, if we only need sample from random, can we just use "from random impo= rt sample"? -Jaben > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of > Yonghong Zhu > Sent: Tuesday, October 30, 2018 6:28 AM > To: edk2-devel@lists.01.org > Cc: Gao, Liming > Subject: [edk2] [Patch] BaseTools: Add special handle for '\' use in Pcd = Value >=20 > From: zhijufan >=20 > Case: > gEfiOzmosisPkgTokenSpaceGuid.PcdBootLogFolderPath|L"\\Logs\\"|VOID* > |12 >=20 > Fixes: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1287 > Cc: Liming Gao > Cc: Yonghong Zhu > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Zhiju.Fan > --- > BaseTools/Source/Python/Common/Expression.py | 13 ++++++++++++- > BaseTools/Source/Python/Common/Misc.py | 9 ++++++--- > 2 files changed, 18 insertions(+), 4 deletions(-) >=20 > 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 >=20 > ERR_STRING_EXPR =3D 'This operator cannot be used in string expr= ession: > [%s].' > ERR_SNYTAX =3D 'Syntax error, the rest of expression cannot= be > evaluated: [%s].' > ERR_MATCH =3D 'No matching right parenthesis.' > ERR_STRING_TOKEN =3D 'Bad string token: [%s].' > @@ -53,10 +54,12 @@ PcdPattern =3D 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 =3D ''.join(random.sample(string.ascii_letters + string.digit= s, 8)) > + String =3D String.replace('\\\\', RanStr).strip() > RetList =3D [] > InSingleQuote =3D False > InDoubleQuote =3D False > Item =3D '' > for i, ch in enumerate(String): > @@ -85,15 +88,20 @@ def SplitString(String): > Item +=3D 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] =3D ch.replace(RanStr,'\\\\') > return RetList >=20 > def SplitPcdValueString(String): > # There might be escaped comma in GUID() or DEVICE_PATH() or " " > # or ' ' or L' ' or L" " > + RanStr =3D ''.join(random.sample(string.ascii_letters + string.digit= s, 8)) > + String =3D String.replace('\\\\', RanStr).strip() > RetList =3D [] > InParenthesis =3D 0 > InSingleQuote =3D False > InDoubleQuote =3D False > Item =3D '' > @@ -122,10 +130,13 @@ def SplitPcdValueString(String): > Item +=3D 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] =3D ch.replace(RanStr,'\\\\') > return RetList >=20 > def IsValidCName(Str): > return True if __ValidString.match(Str) else False >=20 > @@ -388,11 +399,11 @@ class ValueExpression(BaseExpression): > if Val =3D=3D 'L""': > Val =3D False > elif not Val: > Val =3D False > RealVal =3D '""' > - elif not Val.startswith('L"') and not Val.startswith('{') an= d not > Val.startswith("L'"): > + elif not Val.startswith('L"') and not Val.startswith('{') an= d not > Val.startswith("L'") and not Val.startswith("'"): > Val =3D True > RealVal =3D '"' + RealVal + '"' >=20 > # The expression has been parsed, but the end of expression is n= ot > reached > # It means the rest does not comply EBNF of > 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] =3D=3D "'" and Value[-1] =3D=3D "'" and len(list(Value[1= :-1])) > 1: > return True > return False >=20 > def AnalyzePcdExpression(Setting): > - Setting =3D Setting.strip() > + RanStr =3D ''.join(random.sample(string.ascii_letters + string.digit= s, 8)) > + Setting =3D Setting.replace('\\\\', RanStr).strip() > # There might be escaped quote in a string: \", \\\" , \', \\\' > Data =3D Setting > # There might be '|' in string and in ( ... | ... ), replace it with= '-' > NewStr =3D '' > InSingleQuoteStr =3D False > @@ -1267,11 +1268,13 @@ def AnalyzePcdExpression(Setting): > if Pos < 0: > FieldList.append(Setting[StartPos:].strip()) > break > FieldList.append(Setting[StartPos:Pos].strip()) > StartPos =3D Pos + 1 > - > + for i, ch in enumerate(FieldList): > + if RanStr in ch: > + FieldList[i] =3D ch.replace(RanStr,'\\\\') > return FieldList >=20 > def ParseDevPathValue (Value): > if '\\' in Value: > Value.replace('\\', '/').replace(' ', '') > -- > 2.6.1.windows.1 >=20 > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel