public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [Patch V2] BaseTools: Add special handle for '\' use in Pcd Value
@ 2018-10-31  3:49 Yonghong Zhu
  2018-10-31 16:08 ` Carsey, Jaben
  0 siblings, 1 reply; 2+ messages in thread
From: Yonghong Zhu @ 2018-10-31  3:49 UTC (permalink / raw)
  To: edk2-devel; +Cc: zhijufan, Liming Gao

From: zhijufan <zhijux.fan@intel.com>

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>
---
 BaseTools/Source/Python/Common/Expression.py | 14 +++++++++++++-
 BaseTools/Source/Python/Common/Misc.py       |  8 ++++++--
 2 files changed, 19 insertions(+), 3 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 + '"'
 
diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Python/Common/Misc.py
index b32b7cdc5f..3b8efb2e71 100644
--- a/BaseTools/Source/Python/Common/Misc.py
+++ b/BaseTools/Source/Python/Common/Misc.py
@@ -24,6 +24,7 @@ import re
 import pickle
 import array
 import shutil
+from random import sample
 from struct import pack
 from UserDict import IterableUserDict
 from UserList import UserList
@@ -1236,7 +1237,8 @@ def IsFieldValueAnArray (Value):
     return False
 
 def AnalyzePcdExpression(Setting):
-    Setting = Setting.strip()
+    RanStr = ''.join(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 '-'
@@ -1269,7 +1271,9 @@ def AnalyzePcdExpression(Setting):
             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):
-- 
2.18.0.windows.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Patch V2] BaseTools: Add special handle for '\' use in Pcd Value
  2018-10-31  3:49 [Patch V2] BaseTools: Add special handle for '\' use in Pcd Value Yonghong Zhu
@ 2018-10-31 16:08 ` Carsey, Jaben
  0 siblings, 0 replies; 2+ messages in thread
From: Carsey, Jaben @ 2018-10-31 16:08 UTC (permalink / raw)
  To: Zhu, Yonghong, edk2-devel@lists.01.org; +Cc: Gao, Liming

Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>


> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of
> Yonghong Zhu
> Sent: Tuesday, October 30, 2018 8:50 PM
> To: edk2-devel@lists.01.org
> Cc: Gao, Liming <liming.gao@intel.com>
> Subject: [edk2] [Patch V2] BaseTools: Add special handle for '\' use in Pcd
> Value
> 
> From: zhijufan <zhijux.fan@intel.com>
> 
> 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>
> ---
>  BaseTools/Source/Python/Common/Expression.py | 14 +++++++++++++-
>  BaseTools/Source/Python/Common/Misc.py       |  8 ++++++--
>  2 files changed, 19 insertions(+), 3 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 + '"'
> 
> diff --git a/BaseTools/Source/Python/Common/Misc.py
> b/BaseTools/Source/Python/Common/Misc.py
> index b32b7cdc5f..3b8efb2e71 100644
> --- a/BaseTools/Source/Python/Common/Misc.py
> +++ b/BaseTools/Source/Python/Common/Misc.py
> @@ -24,6 +24,7 @@ import re
>  import pickle
>  import array
>  import shutil
> +from random import sample
>  from struct import pack
>  from UserDict import IterableUserDict
>  from UserList import UserList
> @@ -1236,7 +1237,8 @@ def IsFieldValueAnArray (Value):
>      return False
> 
>  def AnalyzePcdExpression(Setting):
> -    Setting = Setting.strip()
> +    RanStr = ''.join(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 '-'
> @@ -1269,7 +1271,9 @@ def AnalyzePcdExpression(Setting):
>              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):
> --
> 2.18.0.windows.1
> 
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-10-31 16:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-10-31  3:49 [Patch V2] BaseTools: Add special handle for '\' use in Pcd Value Yonghong Zhu
2018-10-31 16:08 ` Carsey, Jaben

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox