]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug 5192: esi_parser default is incorrect (#968)
authorAmos Jeffries <yadij@users.noreply.github.com>
Sat, 29 Jan 2022 05:02:38 +0000 (05:02 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Sat, 29 Jan 2022 17:30:21 +0000 (17:30 +0000)
Since commit f5f7786 reversed the internal list order of ESI parser
registry, the esi_parser documentation and code comment in esi/Module.cc
have been incorrect.

Return ESI parsers to the documented default behaviour and make that
default explicit in the code selecting which Parser to initialize.

Also fixed an inverted test that resulted in the esi_parser configured
library _not_ to be the one used.

src/esi/Module.cc
src/esi/Parser.cc

index 9c0d016058815a40a2a798735c9bf73635960fb4..f5eeb4f1682416d4e0f61f5846f26a5627fc5342 100644 (file)
@@ -22,8 +22,6 @@ static ESIParser::Register *prExpat = 0;
 
 void Esi::Init()
 {
-    // register in reverse order of preference.
-    // The latest registered parser will be used as default.
 #if HAVE_LIBEXPAT
     assert(!prExpat); // we should be called once
     prExpat = new ESIParser::Register("expat", &ESIExpatParser::NewParser);
index ed8a375de2ecf49ed9a663fc060edf26581d9096..b923b79d6ebf95b3aed9c5ab763ceff9bcbdd0eb 100644 (file)
@@ -9,6 +9,7 @@
 /* DEBUG: section 86    ESI processing */
 
 #include "squid.h"
+#include "Debug.h"
 #include "esi/Parser.h"
 #include "fatal.h"
 
@@ -25,19 +26,27 @@ ESIParser::GetRegistry()
 ESIParser::Pointer
 ESIParser::NewParser(ESIParserClient *aClient)
 {
-    if (Parser == NULL) {
-        Parser = GetRegistry().front();
-
-        // if type name matters, use it
-        if (strcasecmp(Type, "auto") != 0) {
-            for (auto *p : GetRegistry()) {
-                if (p && strcasecmp(p->name, Type) != 0)
-                    Parser = p;
-            }
+    if (!Parser) {
+        // if esi_parser is configured, use that
+        const char *selectParserName = Type;
+        if (!selectParserName || strcasecmp(selectParserName, "auto") == 0) {
+#if HAVE_LIBXML2
+            // libxml2 is the more secure. prefer when possible
+            selectParserName = "libxml2";
+#else
+            // expat is more widely available
+            selectParserName = "expat";
+#endif
         }
 
-        if (Parser == NULL)
-            fatal ("Unknown ESI Parser type");
+        for (auto *p : GetRegistry()) {
+            if (p && strcasecmp(p->name, selectParserName) == 0)
+                Parser = p;
+        }
+
+        if (!Parser)
+            fatalf("Unknown ESI Parser type '%s'", selectParserName);
+        debugs(86, 2, "selected ESI parser: " << Parser->name);
     }
 
     return (Parser->newParser)(aClient);