Przeglądaj źródła

ConfigParser fix: handle leading whitespace

Hitesh Kanwathirtha 8 lat temu
rodzic
commit
361f3dde09

+ 23 - 15
bin/ch/Helpers.cpp

@@ -257,6 +257,11 @@ HRESULT Helpers::LoadScriptFromFile(LPCSTR filenameToLoad, LPCSTR& contents, UIN
         bufferLength = lengthBytes + sizeof(BYTE);
         pRawBytes = (LPBYTE)malloc(bufferLength);
     }
+    else
+    {
+        bufferLength = 1;
+        pRawBytes = (LPBYTE)malloc(bufferLength);
+    }
 
     if (nullptr == pRawBytes)
     {
@@ -264,24 +269,27 @@ HRESULT Helpers::LoadScriptFromFile(LPCSTR filenameToLoad, LPCSTR& contents, UIN
         IfFailGo(E_OUTOFMEMORY);
     }
 
-    if (file != NULL)
+    if (lengthBytes != 0)
     {
-        //
-        // Read the entire content as a binary block.
-        //
-        size_t readBytes = fread(pRawBytes, sizeof(BYTE), lengthBytes, file);
-        if (readBytes < lengthBytes * sizeof(BYTE))
+        if (file != NULL)
         {
-            IfFailGo(E_FAIL);
+            //
+            // Read the entire content as a binary block.
+            //
+            size_t readBytes = fread(pRawBytes, sizeof(BYTE), lengthBytes, file);
+            if (readBytes < lengthBytes * sizeof(BYTE))
+            {
+                IfFailGo(E_FAIL);
+            }
+        }
+        else // from module source register
+        {
+            // Q: module source is on persistent memory. Why do we use the copy instead?
+            // A: if we use the same memory twice, ch doesn't know that during FinalizeCallback free.
+            // the copy memory will be freed by the finalizer
+            Assert(pRawBytesFromMap);
+            memcpy_s(pRawBytes, bufferLength, pRawBytesFromMap, lengthBytes);
         }
-    }
-    else // from module source register
-    {
-        // Q: module source is on persistent memory. Why do we use the copy instead?
-        // A: if we use the same memory twice, ch doesn't know that during FinalizeCallback free.
-        // the copy memory will be freed by the finalizer
-        Assert(pRawBytesFromMap);
-        memcpy_s(pRawBytes, bufferLength, pRawBytesFromMap, lengthBytes);
     }
 
     if (pRawBytes)

+ 1 - 0
bin/rl/rl.cpp

@@ -2470,6 +2470,7 @@ WriteEnvLst
              NULL,
              NULL,
              NULL,
+             NULL,
              NULL
          };
 

+ 5 - 3
lib/Common/Core/ConfigParser.cpp

@@ -424,15 +424,17 @@ void ConfigParser::ParseConfig(HANDLE hmod, CmdLineArgsParser &parser, const cha
     {
         CharType curChar = ReadChar(configFile);
 
-        if (curChar == EndChar || isspace(curChar))
+        if (curChar == EndChar || isspace(curChar) || curChar == 0)
         {
             configBuffer[index] = 0;
-            if ((err = parser.Parse(configBuffer)) != 0)
+
+            // Parse only if there's something in configBuffer
+            if (index > 0 && (err = parser.Parse(configBuffer)) != 0)
             {
                 break;
             }
 
-            while(curChar != EndChar && isspace(curChar))
+            while(curChar != EndChar && (isspace(curChar) || curChar == 0))
             {
                 curChar = ReadChar(configFile);
             }

+ 0 - 6
test/ConfigParsing/dummy.js

@@ -1,6 +0,0 @@
-//-------------------------------------------------------------------------------------------------------
-// Copyright (C) Microsoft. All rights reserved.
-// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
-//-------------------------------------------------------------------------------------------------------
-
-(function() {})();

+ 0 - 1
test/ConfigParsing/rlexe.xml

@@ -35,5 +35,4 @@
       <custom-config-file>interspersednewline_leadingwhitespace.testconfig</custom-config-file>
     </default>
   </test>
-
 </regress-exe>