From: Brion Vibber Date: Tue, 15 Mar 2011 17:09:20 +0000 (-0700) Subject: Suppress PHP warnings/notices during AtomPub XML parsing to avoid HTTP header problem... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=9e9cbdf505e9ec66c7e9d60bfe170f8d41a146e2;p=quix0rs-gnu-social.git Suppress PHP warnings/notices during AtomPub XML parsing to avoid HTTP header problems when given bad input. If display_errors is on, typical settings would cause PHP error messages to spew to output before the HTTP headers for setting a 400 error go through. Also switched from deprecated static DOMDocument::loadXML() to non-static call. --- diff --git a/actions/apitimelineuser.php b/actions/apitimelineuser.php index 66984b5abd..3fe73c691c 100644 --- a/actions/apitimelineuser.php +++ b/actions/apitimelineuser.php @@ -322,8 +322,11 @@ class ApiTimelineUserAction extends ApiBareAuthAction $this->clientError(_('Atom post must not be empty.')); } - $dom = DOMDocument::loadXML($xml); - if (!$dom) { + $old = error_reporting(error_reporting() & ~(E_WARNING | E_NOTICE)); + $dom = new DOMDocument(); + $ok = $dom->loadXML($xml); + error_reporting($old); + if (!$ok) { // TRANS: Client error displayed attempting to post an API that is not well-formed XML. $this->clientError(_('Atom post must be well-formed XML.')); }