-
Bug
-
Resolution: Fixed
-
Minor
-
4.1.6, 4.2.3, 4.3
-
MOODLE_401_STABLE, MOODLE_402_STABLE, MOODLE_403_STABLE
-
MOODLE_402_STABLE, MOODLE_403_STABLE
-
MDL-80247-403 -
- Covered by automated tests (PHPUnit)
An issue has been identified in the forum grading process, and it may potentially occur elsewhere as well.
Tested on:
- Moodle 4.1.6+ (Build: 20231116)
- Moodle 4.2.3+ (Build: 20231116)
- Moodle 4.3+ (Build: 20231116)
PHP versions:
- PHP 8.0.30
- PHP 8.1.24
Steps to reproduce:
1) Create a graded forum.
2) A student uploads an attached file named "Мазитов А.З. практика тусур.py".
3) When a teacher attempts to assign a grade, an "invalidresponse" error occurs.
Upon further investigation, the following issues were identified:
1) The AJAX function "mod_forum_get_discussion_posts_by_userid" does not return a response.
2) During the service call, a JSON serialization error occurs with the code "JSON_ERROR_UTF8" = "Malformed UTF-8 characters, possibly incorrectly encoded".
3) After examining the service response dump before serialization, it was observed that in the "attachments" array of objects, the field "filenameshort" takes the value "Мазитов А.З. пра..�.py" (corrupted value).
4) Further analysis of the code led to the class "core_files\external\stored_file_exporter", specifically the method "get_other_values", where the "substr()" function is used incorrectly to truncate the file name.
Solution:
Replace the "substr()" calls with "core_text::substr()".
Code:
Before:
if (core_text::strlen($filename) > 25) { |
$filenameshort = shorten_text(substr($filename, 0, -4), 21, true, '..'); |
$filenameshort .= substr($filename, -4); |
}
|
After:
if (core_text::strlen($filename) > 25) { |
$filenameshort = shorten_text(core_text::substr($filename, 0, -4), 21, true, '..'); |
$filenameshort .= core_text::substr($filename, -4); |
}
|