From c428fab04b4b68b16c8c266464246c2928f43d0d Mon Sep 17 00:00:00 2001 From: Stefan Hanauska Date: Mon, 25 Aug 2025 11:05:51 +0200 Subject: [PATCH] MDL-86425 backup: Reset nullcontent flag in xml_writer --- public/backup/util/xml/tests/writer_test.php | 18 ++++++++++++++++++ public/backup/util/xml/xml_writer.class.php | 1 + 2 files changed, 19 insertions(+) diff --git a/public/backup/util/xml/tests/writer_test.php b/public/backup/util/xml/tests/writer_test.php index 947d825fac3..f7533744643 100644 --- a/public/backup/util/xml/tests/writer_test.php +++ b/public/backup/util/xml/tests/writer_test.php @@ -282,6 +282,24 @@ final class writer_test extends \basic_testcase { $result = $xo->get_allcontents(); $this->assertEquals($result, 'testsomecontent'); + // Test nullcontent reset. + $xo = new memory_xml_output(); + $xw = new mock_xml_writer($xo); + $xw->set_prologue(''); + $xw->start(); + $xw->full_tag('tagname', null); + $xw->begin_tag('tagname2'); + $xw->full_tag('tagname3', 'somecontent'); + $xw->end_tag('tagname2'); + $xw->stop(); + $result = $xo->get_allcontents(); + $expected = << + somecontent + + XML; + $this->assertEquals($expected, $result); + // Build a complex XML file and test results against stored file in fixtures $xo = new memory_xml_output(); $xw = new mock_xml_writer($xo); diff --git a/public/backup/util/xml/xml_writer.class.php b/public/backup/util/xml/xml_writer.class.php index da4ed9ebbf2..35be10db1fd 100644 --- a/public/backup/util/xml/xml_writer.class.php +++ b/public/backup/util/xml/xml_writer.class.php @@ -216,6 +216,7 @@ class xml_writer { $this->lastwastext = true; $this->end_tag($tag); } + $this->nullcontent = false; // Reset nullcontent flag. }