-
Bug
-
Resolution: Fixed
-
Major
-
4.2
-
MOODLE_402_STABLE
-
MOODLE_402_STABLE
-
MDL-77959-master -
-
1
-
Team Hedgehog 2023 Sprint 1.4
Currently we strip tags and convert to plaintext, however there are some cases which were discovered during testing aren't covered, such as:
- <br /> being introduced (I think this happens during the current conversion)
- non-tag HTML elements like:
This can be confirmed by including the following in an activity's description, then checking the output of the activity_sender::share_activity (where it is setting $resourcedescription):
<p>This is an example Moodle activity descdription.</p>
|
<p> </p>
|
<p>This is a formatted intro</p>
|
<p> </p>
|
<p>This thing has many lines.</p>
|
<p> </p>
|
<p>The last word of this sentence is in <strong>bold</strong></p> |
I would recommend while troubleshooting this, to copy the relevant cleaning code out to a page and hardcode the initial value, so you can tweak and refresh to see the value without having to go through the share process each time to test it (or output it to error_log).
During my initial investigations, I have not yet found a complete (or elegant) solution, but did find:
- Putting html_entity_decode() inside the strip_tags() line removed the non-breaking spaces.
- Re-running strip-tags after converting to plaintext removed the extra breaks that were introduced, though this didn't seem like a great solution.
- There's still some line breaks included, which do work on the MoodleNet prototype, but I'm not sure if those are acceptable.
During my own testing, this was the result I got to, it would be good if someone can check if there's a more elegant and complete solution (and verify if the newlines being introduced are "safe" for plaintext):
// MoodleNet only accept plaintext descriptions.
|
$resourcedescription = $DB->get_field($this->cminfo->modname, 'intro', ['id' => $this->cminfo->instance]); |
$resourcedescription = strip_tags(html_entity_decode($resourcedescription));
|
$resourcedescription = format_text(
|
$resourcedescription,
|
FORMAT_PLAIN,
|
['context' => $coursecontext] |
);
|
$resourcedescription = strip_tags($resourcedescription);
|
- Discovered while testing
-
MDL-75316 (PARENT) Implement LMS foundation for sharing content to MoodleNet (share activities)
- Closed