michael-milette / moodle-filter_filtercodes

FilterCodes filter for Moodle enables content creators to easily customize and personalize course and site content using plain text tags (no HTML). For premium support, contact us at https://www.tngconsulting.ca/contact
https://moodle.org/plugins/filter_filtercodes
GNU General Public License v3.0
32 stars 43 forks source link

Bug: Filter circular reference leads to fatal error #247

Open tasosb opened 1 year ago

tasosb commented 1 year ago

Prerequisites

What happened?

The plugin doesn't account for possible circular references with certain tags.

For example, a teacher may rename their course to "Test course {coursename}". This will render the course unusable, as when the filter is applied, the course name will be converted "Test course Test course {coursename}" and so on. Moodle will raise a Fatal Error: Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 262144 bytes) in moodle311\lib\moodlelib.php on line 7301

Similarly, adding {coursesummary} to the summary of the course, will render the moodle mobile application unusable. In the website the summary of the course is visible only on the first page, but it has the front page context and the filter prints the site summary (as expected from the instructions). However, in the mobile app, the summary of the course is visible on the course page and thus has the course context, leading to a similar error as above.

What do you think should have happened?

The plugin should prevent possible circular references in the filters.

Steps to reproduce

  1. Login as a teacher
  2. Create a course with the name "Test course {coursename}"
  3. Save the course
  4. Try navigating to the course

Screenshots

No response

Moodle version

Moodle 3.11.11+ (Build: 20221201)

Installed Moodle UI Language packs.

If other language(s), please specify

No response

Workaround

No response

Additional information

No response

System information

No response

Code of Conduct

michael-milette commented 1 year ago

Hi @tasosb ,

Thank you for bringing these issues to my attention. Unfortunately I do not have a quick fix available for you right now because I am not sure how to detect what field the tag is located in.

However, a workaround currently available would be to place square brackets around tags if you do not want them to be interpreted. Example:

Test course [{coursename}]

If you are already experiencing this situation, you could turn FilterCodes off temporarily, update the fields with the square brackets and the re-enable FilterCodes.

Alternatively, you could turn off FilterCodes for a particular course. If you don't want to constantly escape the tags with square brackets.

More information is available in the README.md file included with the plugin.

If you have any suggestions, I would welcome any Pull Requests or suggestions that you might be willing to contribute.

Beat regards,

Michael