Quote values in .ini file
authorChristian Weiske <cweiske@cweiske.de>
Wed, 7 Sep 2016 05:44:39 +0000 (07:44 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Wed, 7 Sep 2016 05:44:39 +0000 (07:44 +0200)
src/shpub/Config.php
src/shpub/Config/Endpoints.php

index 352ab99da68b8194b865e841fa2486a338762e70..d41e45dc2a3495179fb797eb185d471a0b8e015f 100644 (file)
@@ -65,7 +65,8 @@ class Config
                 if ($hostVal == '') {
                     continue;
                 }
                 if ($hostVal == '') {
                     continue;
                 }
-                $str .= $hostProp . '=' . $hostVal . "\n";
+                $str .= $hostProp
+                    . '=' . static::quoteIniValue($hostVal) . "\n";
             }
         }
         $cfgFilePath = $this->getConfigFilePath();
             }
         }
         $cfgFilePath = $this->getConfigFilePath();
@@ -105,5 +106,13 @@ class Config
         }
         return null;
     }
         }
         return null;
     }
+
+    public static function quoteIniValue($val)
+    {
+        if (strpos($val, '=') === false) {
+            return $val;
+        }
+        return '"' . $val . '"';
+    }
 }
 ?>
 }
 ?>
index 2e58e7abd15699c4389ee267bdb7b517add21d60..bc0510e63dcab844ae2684f042465d892ab56b64 100644 (file)
@@ -44,7 +44,7 @@ class Config_Endpoints
         $baseUrl = new \Net_URL2($server);
 
         $doc = new \DOMDocument();
         $baseUrl = new \Net_URL2($server);
 
         $doc = new \DOMDocument();
-        $doc->loadHTMLFile($server);
+        @$doc->loadHTMLFile($server);
         $sx = simplexml_import_dom($doc);
         if ($sx === false) {
             Log::err('Error loading URL: ' . $server);
         $sx = simplexml_import_dom($doc);
         if ($sx === false) {
             Log::err('Error loading URL: ' . $server);
@@ -112,10 +112,11 @@ class Config_Endpoints
 
         file_put_contents(
             $file,
 
         file_put_contents(
             $file,
-            'micropub=' . $this->micropub . "\n"
-            . 'media=' . $this->media . "\n"
-            . 'token=' . $this->token . "\n"
-             . 'authorization=' . $this->authorization . "\n"
+            'micropub=' . Config::quoteIniValue($this->micropub) . "\n"
+            . 'media=' . Config::quoteIniValue($this->media) . "\n"
+            . 'token=' . Config::quoteIniValue($this->token) . "\n"
+            . 'authorization='
+            . Config::quoteIniValue($this->authorization) . "\n"
         );
     }
 
         );
     }