Skip to content

Commit 4d7346d

Browse files
authored
fix: preserve zero values in XML export (#10367)
1 parent 9a75151 commit 4d7346d

4 files changed

Lines changed: 23 additions & 2 deletions

File tree

system/Database/BaseUtils.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ public function getXMLFromResult(ResultInterface $query, array $params = []): st
250250
$xml .= $tab . '<' . $element . '>' . $newline;
251251

252252
foreach ($row as $key => $val) {
253-
$val = empty($val) ? '' : xml_convert((string) $val);
253+
$val = ($val === null || $val === '') ? '' : xml_convert((string) $val);
254254

255255
$xml .= $tab . $tab . '<' . $key . '>' . $val . '</' . $key . '>' . $newline;
256256
}

tests/system/Database/Live/DbUtilsTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,24 @@ public function testUtilsXMLFromResult(): void
205205

206206
$this->assertSame($expected, $actual);
207207
}
208+
209+
public function testUtilsXMLFromResultWithZero(): void
210+
{
211+
$this->db->table('job')->insert([
212+
'name' => '0',
213+
'description' => 'Testing zero value',
214+
]);
215+
$data = $this->db->table('job')->where('name', '0')->get();
216+
217+
$util = (new Database())->loadUtils($this->db);
218+
219+
$data = $util->getXMLFromResult($data);
220+
221+
$expected = '<root><element><id>5</id><name>0</name><description>Testing zero value</description><created_at></created_at><updated_at></updated_at><deleted_at></deleted_at></element></root>';
222+
223+
$actual = preg_replace('#\R+#', '', $data);
224+
$actual = preg_replace('/[ ]{2,}|[\t]/', '', $actual);
225+
226+
$this->assertSame($expected, $actual);
227+
}
208228
}

user_guide_src/source/changelogs/v4.7.4.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ Bugs Fixed
8282
- **Commands:** Fixed a bug where ``spark lang:find`` treated translation keys already provided by the framework or another namespace (such as ``Errors.*`` in ``system/Language``) as new, listing them under ``--show-new`` and writing untranslated placeholders into ``app/Language`` that overrode the existing translations.
8383
- **Config:** Fixed a bug where ``BaseService::injectMock`` did not apply ``strtolower`` consistently, causing inconsistent Service and Mock registration and resolution.
8484
- **Database:** Fixed a bug where ``updateBatch()`` could be called after Query Builder ``where()`` conditions, even though it's not supported. In this situation, now the ``DatabaseException`` is thrown.
85+
- **Database:** Fixed a bug in ``BaseUtils::getXMLFromResult()`` where database values of ``0`` or ``'0'`` were treated as empty and omitted from the generated XML export.
8586
- **Encryption:** Fixed bugs in ``SodiumHandler`` where runtime ``blockSize`` overrides without ``key`` were handled incorrectly, invalid key lengths could leak native Sodium errors, and mismatched decrypt ``blockSize`` values could throw ``SodiumException`` instead of ``EncryptionException``.
8687
- **Filters:** Fixed a bug in ``InvalidChars`` filter where invalid UTF-8 or control characters in array keys were not checked.
8788
- **HTTP:** Fixed a bug where the User Agent library reported Safari's WebKit version instead of the browser version from the ``Version`` token.

utils/phpstan-baseline/empty.notAllowed.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ parameters:
5454

5555
-
5656
message: '#^Construct empty\(\) is not allowed\. Use more strict comparison\.$#'
57-
count: 4
57+
count: 3
5858
path: ../../system/Database/BaseUtils.php
5959

6060
-

0 commit comments

Comments
 (0)