Skip to content

Commit

Permalink
Allow stdClass in XML responses
Browse files Browse the repository at this point in the history
Signed-off-by: jld3103 <jld3103yt@gmail.com>
  • Loading branch information
provokateurin committed Jun 13, 2023
1 parent 39b716c commit 7f46516
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/private/AppFramework/OCS/BaseResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ protected function toXML(array $array, \XMLWriter $writer): void {
$k = 'element';
}

if ($v instanceof \stdClass) {
$v = [];
}

if (\is_array($v)) {
$writer->startElement($k);
$this->toXML($v, $writer);
Expand Down
3 changes: 2 additions & 1 deletion tests/lib/AppFramework/OCS/BaseResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ public function testToXml(): void {
'someElement' => 'withAttribute',
],
'value without key',
'object' => new \stdClass(),
];

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

$this->assertEquals(
"<?xml version=\"1.0\"?>\n<hello>hello</hello><information test=\"some data\"><someElement>withAttribute</someElement></information><element>value without key</element>\n",
"<?xml version=\"1.0\"?>\n<hello>hello</hello><information test=\"some data\"><someElement>withAttribute</someElement></information><element>value without key</element><object/>\n",
$writer->outputMemory(true)
);
}
Expand Down

0 comments on commit 7f46516

Please sign in to comment.