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.126; helo=mga18.intel.com; envelope-from=yonghong.zhu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) (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 709C12245119E for ; Thu, 1 Mar 2018 03:15:19 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Mar 2018 03:21:27 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,408,1515484800"; d="scan'208";a="204702230" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by orsmga005.jf.intel.com with ESMTP; 01 Mar 2018 03:21:27 -0800 Received: from shsmsx104.ccr.corp.intel.com (10.239.4.70) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 1 Mar 2018 03:21:26 -0800 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.116]) by SHSMSX104.ccr.corp.intel.com ([169.254.5.125]) with mapi id 14.03.0319.002; Thu, 1 Mar 2018 19:21:24 +0800 From: "Zhu, Yonghong" To: "Feng, YunhuaX" , "edk2-devel@lists.01.org" CC: "Gao, Liming" , "Zhu, Yonghong" Thread-Topic: [PATCH] BaseTools: Fix eval parse string issue Thread-Index: AdOxA0HAUP6BTkP2QaGvDKjnx2MfxgATBz1Q Date: Thu, 1 Mar 2018 11:21:24 +0000 Message-ID: References: <47C64442C08CCD4089DC43B6B5E46BC482C790@shsmsx102.ccr.corp.intel.com> In-Reply-To: <47C64442C08CCD4089DC43B6B5E46BC482C790@shsmsx102.ccr.corp.intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH] BaseTools: Fix eval parse string issue X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Mar 2018 11:15:19 -0000 Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Reviewed-by: Yonghong Zhu =20 Best Regards, Zhu Yonghong -----Original Message----- From: Feng, YunhuaX=20 Sent: Thursday, March 01, 2018 10:16 AM To: edk2-devel@lists.01.org Cc: Zhu, Yonghong ; Gao, Liming Subject: [PATCH] BaseTools: Fix eval parse string issue eval argument start with " or ', but it is unicode string, will encounter e= rror: List =3D list(eval(Value)) # translate escape character File "", line 1 'j=C3=A0=3D=C3=AE=C2=B5=C2=A2=C3"F=C3=A0 ^ SyntaxError: EOL while scanning string literal Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Yunhua Feng --- BaseTools/Source/Python/Common/Misc.py | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Pyth= on/Common/Misc.py index a7e7797d04..af374d804d 100644 --- a/BaseTools/Source/Python/Common/Misc.py +++ b/BaseTools/Source/Python/Common/Misc.py @@ -1552,37 +1552,59 @@ def ParseFieldValue (Value): raise BadExpression('%s' % Message) Value, Size =3D ParseFieldValue(Value) return Value, 16 if Value.startswith('L"') and Value.endswith('"'): # Unicode String - List =3D list(eval(Value[1:])) # translate escape character + # translate escape character + Value =3D Value[1:] + try: + Value =3D eval(Value) + except: + Value =3D Value[1:-1] + List =3D list(Value) List.reverse() Value =3D 0 for Char in List: Value =3D (Value << 16) | ord(Char) return Value, (len(List) + 1) * 2 if Value.startswith('"') and Value.endswith('"'): # ASCII String - List =3D list(eval(Value)) # translate escape character + # translate escape character + try: + Value =3D eval(Value) + except: + Value =3D Value[1:-1] + List =3D list(Value) List.reverse() Value =3D 0 for Char in List: Value =3D (Value << 8) | ord(Char) return Value, len(List) + 1 if Value.startswith("L'") and Value.endswith("'"): # Unicode Character Constant - List =3D list(eval(Value[1:])) # translate escape character + # translate escape character + Value =3D Value[1:] + try: + Value =3D eval(Value) + except: + Value =3D Value[1:-1] + List =3D list(Value) if len(List) =3D=3D 0: raise BadExpression('Length %s is %s' % (Value, len(List))) List.reverse() Value =3D 0 for Char in List: Value =3D (Value << 16) | ord(Char) return Value, len(List) * 2 if Value.startswith("'") and Value.endswith("'"): # Character constant - List =3D list(eval(Value)) # translate escape character + # translate escape character + try: + Value =3D eval(Value) + except: + Value =3D Value[1:-1] + List =3D list(Value) if len(List) =3D=3D 0: raise BadExpression('Length %s is %s' % (Value, len(List))) List.reverse() Value =3D 0 for Char in List: -- 2.12.2.windows.2