diff --git a/backup/util/xml/tests/writer_test.php b/backup/util/xml/tests/writer_test.php
index 947d825fac3..f7533744643 100644
--- a/backup/util/xml/tests/writer_test.php
+++ b/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/backup/util/xml/xml_writer.class.php b/backup/util/xml/xml_writer.class.php
index da4ed9ebbf2..35be10db1fd 100644
--- a/backup/util/xml/xml_writer.class.php
+++ b/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.
}