]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Application/Shell/ShellParametersProtocol.c
ShellPkg: Don't strip positional parameters of quotation marks.
[mirror_edk2.git] / ShellPkg / Application / Shell / ShellParametersProtocol.c
index 9c502f8f212e70290706b18c874b02582bb8fbb4..56dd79214b3ad8363cb396190d06095cf91af560 100644 (file)
@@ -74,10 +74,12 @@ FindEndOfParameter(
 \r
   This will also remove all remaining ^ characters after processing.\r
 \r
-  @param[in, out] Walker        pointer to string of command line.  Adjusted to\r
-                                reminaing command line on return\r
-  @param[in, out] TempParameter pointer to string of command line item extracted.\r
-  @param[in]      Length        buffer size of TempParameter.\r
+  @param[in, out] Walker          pointer to string of command line.  Adjusted to\r
+                                  reminaing command line on return\r
+  @param[in, out] TempParameter   pointer to string of command line item extracted.\r
+  @param[in]      Length          buffer size of TempParameter.\r
+  @param[in]      StripQuotation  if TRUE then strip the quotation marks surrounding\r
+                                  the parameters.\r
 \r
   @return   EFI_INALID_PARAMETER  A required parameter was NULL or pointed to a NULL or empty string.\r
   @return   EFI_NOT_FOUND         A closing " could not be found on the specified string\r
@@ -87,7 +89,8 @@ EFIAPI
 GetNextParameter(\r
   IN OUT CHAR16   **Walker,\r
   IN OUT CHAR16   **TempParameter,\r
-  IN CONST UINTN  Length\r
+  IN CONST UINTN  Length,\r
+  IN BOOLEAN      StripQuotation\r
   )\r
 {\r
   CONST CHAR16 *NextDelim;\r
@@ -161,7 +164,11 @@ DEBUG_CODE_END();
       //\r
       // eliminate the unescaped quote\r
       //\r
-      CopyMem ((CHAR16*)NextDelim, NextDelim + 1, StrSize (NextDelim + 1));\r
+      if (StripQuotation) {\r
+        CopyMem ((CHAR16*)NextDelim, NextDelim + 1, StrSize (NextDelim + 1));\r
+         } else{\r
+        NextDelim++;\r
+         }\r
     }\r
   }\r
 \r
@@ -178,9 +185,11 @@ DEBUG_CODE_END();
   All special character processing (alias, environment variable, redirection, \r
   etc... must be complete before calling this API.\r
 \r
-  @param[in] CommandLine         String of command line to parse\r
-  @param[in, out] Argv           pointer to array of strings; one for each parameter\r
-  @param[in, out] Argc           pointer to number of strings in Argv array\r
+  @param[in] CommandLine          String of command line to parse\r
+  @param[in] StripQuotation       if TRUE then strip the quotation marks surrounding\r
+                                  the parameters.\r
+  @param[in, out] Argv            pointer to array of strings; one for each parameter\r
+  @param[in, out] Argc            pointer to number of strings in Argv array\r
 \r
   @return EFI_SUCCESS           the operation was sucessful\r
   @return EFI_OUT_OF_RESOURCES  a memory allocation failed.\r
@@ -189,8 +198,9 @@ EFI_STATUS
 EFIAPI\r
 ParseCommandLineToArgs(\r
   IN CONST CHAR16 *CommandLine,\r
-  IN OUT CHAR16 ***Argv,\r
-  IN OUT UINTN *Argc\r
+  IN BOOLEAN      StripQuotation,\r
+  IN OUT CHAR16   ***Argv,\r
+  IN OUT UINTN    *Argc\r
   )\r
 {\r
   UINTN       Count;\r
@@ -228,7 +238,7 @@ ParseCommandLineToArgs(
       ; Walker != NULL && *Walker != CHAR_NULL\r
       ; Count++\r
       ) {\r
-    if (EFI_ERROR(GetNextParameter(&Walker, &TempParameter, Size))) {\r
+    if (EFI_ERROR(GetNextParameter(&Walker, &TempParameter, Size, TRUE))) {\r
       break;\r
     }\r
   }\r
@@ -246,7 +256,7 @@ ParseCommandLineToArgs(
   Walker = (CHAR16*)NewCommandLine;\r
   while(Walker != NULL && *Walker != CHAR_NULL) {\r
     SetMem16(TempParameter, Size, CHAR_NULL);\r
-    if (EFI_ERROR(GetNextParameter(&Walker, &TempParameter, Size))) {\r
+    if (EFI_ERROR(GetNextParameter(&Walker, &TempParameter, Size, StripQuotation))) {\r
       Status = EFI_INVALID_PARAMETER;\r
       goto Done;\r
     }\r
@@ -375,6 +385,7 @@ CreatePopulateInstallShellParametersProtocol (
     // Populate Argc and Argv\r
     //\r
     Status = ParseCommandLineToArgs(FullCommandLine,\r
+                                    TRUE,\r
                                     &(*NewShellParameters)->Argv,\r
                                     &(*NewShellParameters)->Argc);\r
 \r
@@ -1369,6 +1380,7 @@ RestoreStdInStdOutStdErr (
 \r
   @param[in, out] ShellParameters        Pointer to parameter structure to modify.\r
   @param[in] NewCommandLine              The new command line to parse and use.\r
+  @param[in] Type                        The type of operation.\r
   @param[out] OldArgv                    Pointer to old list of parameters.\r
   @param[out] OldArgc                    Pointer to old number of items in Argv list.\r
 \r
@@ -1380,11 +1392,15 @@ EFIAPI
 UpdateArgcArgv(\r
   IN OUT EFI_SHELL_PARAMETERS_PROTOCOL  *ShellParameters,\r
   IN CONST CHAR16                       *NewCommandLine,\r
+  IN SHELL_OPERATION_TYPES              Type,\r
   OUT CHAR16                            ***OldArgv OPTIONAL,\r
   OUT UINTN                             *OldArgc OPTIONAL\r
   )\r
 {\r
+  BOOLEAN                 StripParamQuotation;\r
+  \r
   ASSERT(ShellParameters != NULL);\r
+  StripParamQuotation = TRUE;\r
 \r
   if (OldArgc != NULL) {\r
     *OldArgc = ShellParameters->Argc;\r
@@ -1393,7 +1409,15 @@ UpdateArgcArgv(
     *OldArgv = ShellParameters->Argv;\r
   }\r
 \r
-  return (ParseCommandLineToArgs(NewCommandLine, &(ShellParameters->Argv), &(ShellParameters->Argc)));\r
+  if (Type == Script_File_Name) {\r
+    StripParamQuotation = FALSE;\r
+  }\r
+  \r
+  return ParseCommandLineToArgs( NewCommandLine, \r
+                                 StripParamQuotation, \r
+                                 &(ShellParameters->Argv), \r
+                                 &(ShellParameters->Argc)\r
+                                );\r
 }\r
 \r
 /**\r