Skip to content

Commit 38d64f4

Browse files
Merge pull request #38745 from nextcloud/feature/ocs-xml-stdclass
Allow stdClass in XML responses
2 parents 3f766e9 + 7f46516 commit 38d64f4

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

lib/private/AppFramework/OCS/BaseResponse.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ protected function toXML(array $array, \XMLWriter $writer): void {
143143
$k = 'element';
144144
}
145145

146+
if ($v instanceof \stdClass) {
147+
$v = [];
148+
}
149+
146150
if (\is_array($v)) {
147151
$writer->startElement($k);
148152
$this->toXML($v, $writer);

tests/lib/AppFramework/OCS/BaseResponseTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@ public function testToXml(): void {
4545
'someElement' => 'withAttribute',
4646
],
4747
'value without key',
48+
'object' => new \stdClass(),
4849
];
4950

5051
$this->invokePrivate($response, 'toXml', [$data, $writer]);
5152
$writer->endDocument();
5253

5354
$this->assertEquals(
54-
"<?xml version=\"1.0\"?>\n<hello>hello</hello><information test=\"some data\"><someElement>withAttribute</someElement></information><element>value without key</element>\n",
55+
"<?xml version=\"1.0\"?>\n<hello>hello</hello><information test=\"some data\"><someElement>withAttribute</someElement></information><element>value without key</element><object/>\n",
5556
$writer->outputMemory(true)
5657
);
5758
}

0 commit comments

Comments
 (0)