Don't return invalid XML from paraminfo when one of parameter values is null
authorPetr Onderka <gsvick@gmail.com>
Wed, 23 Jan 2013 20:55:39 +0000 (21:55 +0100)
committerPetr Onderka <gsvick@gmail.com>
Thu, 24 Jan 2013 10:39:05 +0000 (11:39 +0100)
The module setglobalaccountstatus currently has null
as one of the values for one of its parameters,
which causes paraminfo to return invalid XML (unclosed tag).

I believe values shouldn't be null, but paraminfo
shouldn't return invalid XML even when they are.

This problem occured only with values that go into element content,
those that are rendered as attributes were already fine.

This change modifies ApiFormatXml, so it affects all modules.

Change-Id: Ibf5c329e7bfa375b06f0976ebb9e449f2cb1c927

includes/api/ApiFormatXml.php

index 582e405..8dbeae4 100644 (file)
@@ -205,7 +205,13 @@ class ApiFormatXml extends ApiFormatBase {
                                // ignore
                                break;
                        default:
-                               $retval .= $indstr . Xml::element( $elemName, null, $elemValue );
+                               // to make sure null value doesn't produce unclosed element,
+                               // which is what Xml::element( $elemName, null, null ) returns
+                               if ( $elemValue === null ) {
+                                       $retval .= $indstr . Xml::element( $elemName );
+                               } else {
+                                       $retval .= $indstr . Xml::element( $elemName, null, $elemValue );
+                               }
                                break;
                }
                return $retval;