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 45 forks source link

Bug: {qrcode} and {urlencode} not processed after replacement tags #302

Closed 28Smiles closed 3 months ago

28Smiles commented 3 months ago

Prerequisites

What happened?

Using tags within urlencode or qrcode are not replaced with their content and whitespace is encoded with + instead of %2B (Unlike specified in RFC 3986). Example: {urlencode}Test {coursename}{/urlencode} Result: Test+%7Bcoursename%7D

For a RFC 3986 compliant encoding use rawurlencode, either we change this or provide an additional tag.

What do you think should have happened?

I expected Test%2BThis%2Bis%2Ba%2Bcourse

Steps to reproduce

  1. Create a course
  2. Create an activity
  3. Enable the filter
  4. Use the sample provided ({urlencode}Test {coursename}{/urlencode})
  5. Save
  6. Look at the result

Screenshots

No response

Moodle version

Moodle 4.4.2+

Installed Moodle UI Language packs.

If other language(s), please specify

No response

Workaround

No response

Additional information

No response

System information

Client Device type: (e.g. Desktop, iPhone or iPad, Android phone or tablet, Other - specify) Client Operating System: (e.g. Windows, Linux, Mac OS, Android, iOS, Other - specify) Client Web Browser: (e.g. Chrome, Edge, Firefox, Safari, Safe Exam Browser, Moodle Mobile App) Server Operating System: (e.g. Windows, Linux, Mac OS, Other - specify) Server Webserver: (e.g. Apache, Nginx, IIS, Other - specify) Server PHP: (e.g. 7.4, 8.0, 8.1, 8.2, 8.3, Other - specify)

Code of Conduct

28Smiles commented 3 months ago

If you tell me which version you prefer, I would try to file a patch

michael-milette commented 3 months ago

Hi @28Smiles ,

Sorry, for not responding sooner. I was off sick.

I did take a look at your issue and was able to understand and reproduce it. The bug is a matter of code execution order. The {coursename} tag needs to be processed before the {urlencode} tags. It is a matter of shifting code around. Last year I though I worked through this for most tags but I guess this one escaped me.

You are welcome to submit a PR. However, I am not clear about your question regarding "which version I prefer". Can you clarify?

Best regards,

Michael

28Smiles commented 3 months ago

The php function urlencode is not the one adhering to RFC 8936, therefore it would be nice to use rawurlencode either by changing the implementation or creation of a new tag for this version.

michael-milette commented 3 months ago

Thank you Leon for fixing this issue.