Fix xmlns and schemaLocation argument order in `XMLWriter`
authorMatthias Schmidt <gravatronics@live.com>
Mon, 15 Oct 2018 17:25:23 +0000 (19:25 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Mon, 15 Oct 2018 17:25:23 +0000 (19:25 +0200)
See #2545

wcfsetup/install/files/lib/util/XMLWriter.class.php

index 97eea1d0bebb817c44e6b5cb1cd64bb876bce28a..9450d5cf38329be6a0112349797b20a5cdd903ed 100644 (file)
@@ -52,11 +52,18 @@ class XMLWriter {
                
                $this->xml->startDocument('1.0', 'UTF-8');
                $this->startElement($rootElement);
-               $attributes = array_merge($attributes, [
-                       'xmlns' => $namespace,
-                       'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
-                       'xsi:schemaLocation' => $namespace . ' ' . $schemaLocation
-               ]);
+               $attributes = array_merge(
+                       [
+                               'xmlns' => $namespace,
+                               'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
+                               'xsi:schemaLocation' => $namespace . ' ' . $schemaLocation
+                       ],
+                       // `xmlns`, `xmlns:xsi`, and `xsi:schemaLocation` are explicitly set
+                       // as first attributes in that order 
+                       array_filter($attributes, function($attributeName) {
+                               return !in_array($attributeName, ['xmlns', 'xmlns:xsi', 'xsi:schemaLocation']);
+                       }, ARRAY_FILTER_USE_KEY)
+               );
                $this->writeAttributes($attributes);
                
                $this->activeDocument = true;