Merge branch 'MDL-72762_310' of https://github.com/stronk7/moodle into MOODLE_310_STABLE

This commit is contained in:
Sara Arjona
2022-02-16 11:50:24 +01:00
3 changed files with 26 additions and 9 deletions
+4
View File
@@ -1,6 +1,10 @@
This files describes API changes in /backup/*,
information provided here is intended especially for developers.
=== 3.10.10 ===
* Backup UI labels now accept empty/whitespace-only contents.
=== 3.10 ===
* Local plugins can now hook into a backup and restore process of grade items by
using define_grade_item_plugin_structure method (See MDL-69418).
+6 -1
View File
@@ -146,7 +146,12 @@ class base_setting_ui {
* @throws base_setting_ui_exception when the label is not valid.
* @param string $label
*/
public function set_label(string $label) :void {
public function set_label(string $label): void {
// Let's avoid empty/whitespace-only labels, so the html clean (that makes trim()) doesn't fail.
if (trim($label) === '') {
$label = ' '; // Will be converted to non-breaking utf-8 char 0xc2a0 by PARAM_CLEANHTML.
}
$label = clean_param($label, PARAM_CLEANHTML);
if ($label === '') {
+16 -8
View File
@@ -58,13 +58,21 @@ class base_setting_ui_test extends advanced_testcase {
$bsui->set_label(123);
$this->assertSame('123', $bsui->get_label());
// Should raise an exception when label is empty.
try {
$bsui->set_label('');
$this->assertTrue(false, 'base_setting_ui_exception');
} catch (Exception $exception) {
$this->assertTrue($exception instanceof base_setting_ui_exception);
$this->assertEquals($exception->errorcode, 'setting_invalid_ui_label');
}
// Should be converted to non-breaking space (U+00A0) when label is empty.
$bsui->set_label('');
$this->assertSame("\u{00A0}", $bsui->get_label());
// Should be converted to non-breaking space (U+00A0) when the trimmed label is empty.
$bsui->set_label(" \t\t\n\n\t\t ");
$this->assertSame("\u{00A0}", $bsui->get_label());
// Should clean partially the wrong bits.
$bsui->set_label('<b onmouseover=alert("test")>label</b>');
$this->assertSame('<b>label</b>', $bsui->get_label());
// Should raise an exception when cleaning ends with 100% empty.
$this->expectException(base_setting_ui_exception::class);
$this->expectExceptionMessage('error/setting_invalid_ui_label');
$bsui->set_label('<script>alert("test")</script>');
}
}