summaryrefslogtreecommitdiffstats
path: root/BaseTools/Source/Python/Common/String.py
diff options
context:
space:
mode:
authorFeng, YunhuaX </o=Intel/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Recipients/cn=Feng, YunhuaX4e1>2018-02-26 16:42:30 +0800
committerYonghong Zhu <yonghong.zhu@intel.com>2018-02-28 08:47:11 +0800
commitea927d2f3f2e34f4b26c10829f5887830cb0720e (patch)
treec7c28de62b6414ad06a61952dcd7f904407995fb /BaseTools/Source/Python/Common/String.py
parentf0c69b614cf56df1e7908574111d92864ca3ee9c (diff)
downloadedk2-ea927d2f3f2e34f4b26c10829f5887830cb0720e.tar.gz
edk2-ea927d2f3f2e34f4b26c10829f5887830cb0720e.tar.bz2
edk2-ea927d2f3f2e34f4b26c10829f5887830cb0720e.zip
BaseTools: Fix flexible PCD single quote and double quote bugs
1.The " and ' inside the string, must use escape character format (\", \') 2.'string' and L'string' format in --pcd, it must be double quoted first. Some examples that to match --pcd format and DSC format --pcd DSC format L"ABC" L"ABC" "AB\\\"C" "AB\"C" "AB\\\'C" "AB\'C" L"\'AB\\\"C\'" L'AB\"C' "\'AB\\\'C\'" 'AB\'C' H"{0, L\"AB\\\"B\", \'ab\\\"c\'}" {0, L"AB\"B", 'ab\"c'} Cc: Liming Gao <liming.gao@intel.com> Cc: Yonghong Zhu <yonghong.zhu@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Yunhua Feng <yunhuax.feng@intel.com> Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
Diffstat (limited to 'BaseTools/Source/Python/Common/String.py')
-rw-r--r--BaseTools/Source/Python/Common/String.py46
1 files changed, 29 insertions, 17 deletions
diff --git a/BaseTools/Source/Python/Common/String.py b/BaseTools/Source/Python/Common/String.py
index 4a8c03e88e..5e50beff5c 100644
--- a/BaseTools/Source/Python/Common/String.py
+++ b/BaseTools/Source/Python/Common/String.py
@@ -45,26 +45,32 @@ def GetSplitValueList(String, SplitTag=DataType.TAB_VALUE_SPLIT, MaxSplit= -1):
ValueList = []
Last = 0
Escaped = False
- InString = False
+ InSingleQuoteString = False
+ InDoubleQuoteString = False
InParenthesis = 0
for Index in range(0, len(String)):
Char = String[Index]
if not Escaped:
# Found a splitter not in a string, split it
- if not InString and InParenthesis == 0 and Char == SplitTag:
+ if (not InSingleQuoteString or not InDoubleQuoteString) and InParenthesis == 0 and Char == SplitTag:
ValueList.append(String[Last:Index].strip())
Last = Index + 1
if MaxSplit > 0 and len(ValueList) >= MaxSplit:
break
- if Char == '\\' and InString:
+ if Char == '\\' and (InSingleQuoteString or InDoubleQuoteString):
Escaped = True
- elif Char == '"':
- if not InString:
- InString = True
+ elif Char == '"' and not InSingleQuoteString:
+ if not InDoubleQuoteString:
+ InDoubleQuoteString = True
else:
- InString = False
+ InDoubleQuoteString = False
+ elif Char == "'" and not InDoubleQuoteString:
+ if not InSingleQuoteString:
+ InSingleQuoteString = True
+ else:
+ InSingleQuoteString = False
elif Char == '(':
InParenthesis = InParenthesis + 1
elif Char == ')':
@@ -345,14 +351,17 @@ def CleanString(Line, CommentCharacter=DataType.TAB_COMMENT_SPLIT, AllowCppStyle
#
# remove comments, but we should escape comment character in string
#
- InString = False
+ InDoubleQuoteString = False
+ InSingleQuoteString = False
CommentInString = False
for Index in range(0, len(Line)):
- if Line[Index] == '"':
- InString = not InString
- elif Line[Index] == CommentCharacter and InString :
+ if Line[Index] == '"' and not InSingleQuoteString:
+ InDoubleQuoteString = not InDoubleQuoteString
+ elif Line[Index] == "'" and not InDoubleQuoteString:
+ InSingleQuoteString = not InSingleQuoteString
+ elif Line[Index] == CommentCharacter and (InSingleQuoteString or InDoubleQuoteString):
CommentInString = True
- elif Line[Index] == CommentCharacter and not InString :
+ elif Line[Index] == CommentCharacter and not (InSingleQuoteString or InDoubleQuoteString):
Line = Line[0: Index]
break
@@ -402,15 +411,18 @@ def CleanString2(Line, CommentCharacter=DataType.TAB_COMMENT_SPLIT, AllowCppStyl
#
# separate comments and statements, but we should escape comment character in string
#
- InString = False
+ InDoubleQuoteString = False
+ InSingleQuoteString = False
CommentInString = False
Comment = ''
for Index in range(0, len(Line)):
- if Line[Index] == '"':
- InString = not InString
- elif Line[Index] == CommentCharacter and InString:
+ if Line[Index] == '"' and not InSingleQuoteString:
+ InDoubleQuoteString = not InDoubleQuoteString
+ elif Line[Index] == "'" and not InDoubleQuoteString:
+ InSingleQuoteString = not InSingleQuoteString
+ elif Line[Index] == CommentCharacter and (InDoubleQuoteString or InSingleQuoteString):
CommentInString = True
- elif Line[Index] == CommentCharacter and not InString:
+ elif Line[Index] == CommentCharacter and not (InDoubleQuoteString or InSingleQuoteString):
Comment = Line[Index:].strip()
Line = Line[0:Index].strip()
break