BaseTools/UPT: Fix an issue of UNI string checking.

The tool now can detect the error that the content between double
quotes contains another double quotes or enter key.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hess Chen <hesheng.chen@intel.com>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
This commit is contained in:
Hess Chen 2018-10-16 14:04:00 +08:00 committed by Yonghong Zhu
parent 7a57490c2e
commit 90c64aada8
1 changed files with 23 additions and 0 deletions

View File

@ -566,6 +566,22 @@ class UniFileClassObject(object):
if Line.startswith(u'#language') and len(Line.split()) == 2: if Line.startswith(u'#language') and len(Line.split()) == 2:
MultiLineFeedExits = True MultiLineFeedExits = True
#
# Check the situation that there only has one '"' for the language entry
#
if Line.startswith(u'#string') and Line.find(u'#language') > 0 and Line.count(u'"') == 1:
EdkLogger.Error("Unicode File Parser", ToolError.FORMAT_INVALID,
ExtraData='''The line %s misses '"' at the end of it in file %s'''
% (LineCount, File.Path))
#
# Check the situation that there has more than 2 '"' for the language entry
#
if Line.startswith(u'#string') and Line.find(u'#language') > 0 and Line.replace(u'\\"', '').count(u'"') > 2:
EdkLogger.Error("Unicode File Parser", ToolError.FORMAT_INVALID,
ExtraData='''The line %s has more than 2 '"' for language entry in file %s'''
% (LineCount, File.Path))
# #
# Between two String entry, can not contain line feed # Between two String entry, can not contain line feed
# #
@ -727,6 +743,13 @@ class UniFileClassObject(object):
else: else:
EdkLogger.Error("Unicode File Parser", ToolError.FORMAT_INVALID, ExtraData=File.Path) EdkLogger.Error("Unicode File Parser", ToolError.FORMAT_INVALID, ExtraData=File.Path)
elif Line.startswith(u'"'): elif Line.startswith(u'"'):
#
# Check the situation that there has more than 2 '"' for the language entry
#
if Line.replace(u'\\"', '').count(u'"') > 2:
EdkLogger.Error("Unicode File Parser", ToolError.FORMAT_INVALID,
ExtraData='''The line %s has more than 2 '"' for language entry in file %s'''
% (LineCount, File.Path))
if u'#string' in Line or u'#language' in Line: if u'#string' in Line or u'#language' in Line:
EdkLogger.Error("Unicode File Parser", ToolError.FORMAT_INVALID, ExtraData=File.Path) EdkLogger.Error("Unicode File Parser", ToolError.FORMAT_INVALID, ExtraData=File.Path)
NewLines.append(Line) NewLines.append(Line)