ShellPkg: Handle escape characters properly for parse command

parse command does not remove escape character ^ if used to pass special characters like ^ , “ in a quoted -sfo output string. 

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Tapan Shah <tapandshah@hp.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>



git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17556 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Tapan Shah 2015-06-03 20:34:48 +00:00 committed by jcarsey
parent 421fbf99f8
commit 307f2ce4e8
1 changed files with 52 additions and 2 deletions

View File

@ -188,6 +188,52 @@ ParseReturnStdInLine (
return (RetVal); return (RetVal);
} }
/**
Handle stings for SFO Output with escape character ^ in a string
1. Quotation marks in the string must be escaped by using a ^ character (i.e. ^).
2. The ^ character may be inserted using ^^.
@param[in] String The Unicode NULL-terminated string.
@retval NewString The new string handled for SFO.
**/
EFI_STRING
HandleStringWithEscapeCharForParse (
IN CHAR16 *String
)
{
EFI_STRING NewStr;
EFI_STRING StrWalker;
EFI_STRING ReturnStr;
if (String == NULL) {
return NULL;
}
//
// start to parse the input string.
//
NewStr = AllocateZeroPool (StrSize (String));
if (NewStr == NULL) {
return NULL;
}
ReturnStr = NewStr;
StrWalker = String;
while (*StrWalker != CHAR_NULL) {
if (*StrWalker == L'^' && (*(StrWalker + 1) == L'^' || *(StrWalker + 1) == L'"')) {
*NewStr = *(StrWalker + 1);
StrWalker++;
} else {
*NewStr = *StrWalker;
}
StrWalker++;
NewStr++;
}
return ReturnStr;
}
/** /**
Do the actual parsing of the file. the file should be SFO output from a Do the actual parsing of the file. the file should be SFO output from a
shell command or a similar format. shell command or a similar format.
@ -222,6 +268,7 @@ PerformParsing(
CHAR16 *ColumnPointer; CHAR16 *ColumnPointer;
SHELL_STATUS ShellStatus; SHELL_STATUS ShellStatus;
CHAR16 *TempSpot; CHAR16 *TempSpot;
CHAR16 *SfoString;
ASSERT(FileName != NULL); ASSERT(FileName != NULL);
ASSERT(TableName != NULL); ASSERT(TableName != NULL);
@ -299,8 +346,11 @@ PerformParsing(
if (ColumnPointer != NULL && *ColumnPointer != CHAR_NULL && ColumnPointer[StrLen (ColumnPointer) - 1] == L'\"'){ if (ColumnPointer != NULL && *ColumnPointer != CHAR_NULL && ColumnPointer[StrLen (ColumnPointer) - 1] == L'\"'){
ColumnPointer[StrLen (ColumnPointer) - 1] = CHAR_NULL; ColumnPointer[StrLen (ColumnPointer) - 1] = CHAR_NULL;
} }
SfoString = HandleStringWithEscapeCharForParse (ColumnPointer);
ShellPrintEx (-1, -1, L"%s\r\n", ColumnPointer); if (SfoString != NULL) {
ShellPrintEx (-1, -1, L"%s\r\n", SfoString);
SHELL_FREE_NON_NULL (SfoString);
}
} }
} }
} }