]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Work around weird bug with HTML normalization via PHP DOM module; if source had xmlns...
authorBrion Vibber <brion@pobox.com>
Fri, 19 Mar 2010 00:55:21 +0000 (17:55 -0700)
committerBrion Vibber <brion@pobox.com>
Fri, 19 Mar 2010 00:57:58 +0000 (17:57 -0700)
plugins/OStatus/extlib/hkit/hkit.class.php
plugins/OStatus/lib/discoveryhints.php

index c3a54cff65bb1ed3ddac22fb62c8e6dc2cb75b57..fec6f4d8fd694c2a89b1ca57d6289aaa10cee67f 100644 (file)
        }
 
 
-?>
\ No newline at end of file
+?>
index 4da2ec0f1e7cf375c95f1e9eff56bb2ded9efe99..0273b5a92c85d2cd56a6d4a5076c88f08be88ea7 100644 (file)
@@ -174,6 +174,26 @@ class DiscoveryHints {
         error_reporting($old);
         
         if ($ok) {
+            // If the original had xmlns or xml:lang attributes on the
+            // <html>, we seen to end up with duplicates, which causes
+            // parse errors. Remove em!
+            //
+            // For some reason we have to iterate and remove them twice,
+            // *plus* they don't show up on hasAttribute() or removeAttribute().
+            // This might be some weird bug in PHP or libxml2, uncertain if
+            // it affects other folks consistently.
+            $root = $dom->documentElement;
+            foreach ($root->attributes as $i => $x) {
+                if ($i == 'xmlns' || $i == 'xml:lang') {
+                    $root->removeAttributeNode($x);
+                }
+            }
+            foreach ($root->attributes as $i => $x) {
+                if ($i == 'xmlns' || $i == 'xml:lang') {
+                    $root->removeAttributeNode($x);
+                }
+            }
+
             // hKit doesn't give us a chance to pass the source URL for
             // resolving relative links, such as the avatar photo on a
             // Google profile. We'll slip it into a <base> tag if there's
@@ -192,7 +212,6 @@ class DiscoveryHints {
                     $head = $heads->item(0);
                 } else {
                     $head = $dom->createElement('head');
-                    $root = $dom->documentRoot;
                     if ($root->firstChild) {
                         $root->insertBefore($head, $root->firstChild);
                     } else {