Skip to content

fix: stop double HTML-escaping course name in enrollment emails#754

Draft
Waleed-Mujahid wants to merge 1 commit into
develop-koafrom
fix/koa-enroll-email-double-html-escape
Draft

fix: stop double HTML-escaping course name in enrollment emails#754
Waleed-Mujahid wants to merge 1 commit into
develop-koafrom
fix/koa-enroll-email-double-html-escape

Conversation

@Waleed-Mujahid

Copy link
Copy Markdown
Member

Problem

Course titles containing & (or <, >, ") render as CICT&amp;L in instructor enrollment/beta emails. Reported on Koa for a course named "Cambridge International Certificate in Teaching & Learning CICT&L 5881 Unit One (Pilot)".

Root cause — two escapes stacked

  1. Python: get_email_params / send_mail_to_student wrapped course_name in Text() (= markupsafe.escape) → & becomes &amp;.
  2. Template: in the edx-ace HTML bodies, {% blocktrans %} runs under autoescape-on and was wrapped in {% filter force_escape %} → escapes a second time → &amp;amp; → renders &amp;.

The subject and body.txt use {% autoescape off %}, so removing Text() alone fixed those; the HTML body needed the template change too.

Fix

  • Drop the Text() wrapper on course_name (both call sites) — templates own the escaping.
  • In the 7 instructor body.html templates, switch course_name blocktrans blocks from {% filter force_escape %} to {% autoescape off %} + xss-lint disable.

Backport of upstream openedx/edx-platform#31995 ("fix subject email and body html code"), which fixed this on master but was never backported to the Koa release line. Cherry-pick isn't viable — that commit sits on 2023 master and conflicts across the whole repo on Koa.

Coverage / notes

  • All 7 instructor email types: allowed/enrolled enroll+unenroll, add/remove beta tester, account-creation-and-enrollment.
  • Converts one block fix: fix subject email and body html code openedx/openedx-platform#31995 missed: account-creation "Sincerely yours, The {course_name} Team".
  • Leaves as upstream: the addbetatester {% blocktrans asvar course_cta_text %}Visit {{ course_name }}{% endblocktrans %} block — different render path (feeds the CTA include); upstream left it untouched.

Testing

Not run locally — Koa devstack not up in this environment. Relies on CI. No behavior change beyond escaping of course_name in these emails.

Backport of openedx#31995 to Koa.

Course titles containing '&' (or <, >, ") rendered as "CICT&amp;L" in
instructor enrollment/beta emails. Two escapes stacked:
- get_email_params / send_mail_to_student pre-escaped course_name with
  Text() (markupsafe.escape); and
- the edx-ace body.html templates escaped it again -- {% blocktrans %} runs
  under autoescape-on AND was wrapped in {% filter force_escape %}.

Drop the Text() wrapper (templates own the escaping) and, in the HTML
bodies, switch the course_name blocktrans blocks from force_escape to
{% autoescape off %} + xss-lint disable, matching openedx#31995. Subject and
body.txt already use {% autoescape off %}, so removing Text() sufficed there.

Also converts one block openedx#31995 missed: accountcreationandenrollment
"Sincerely yours, The {course_name} Team". The addbetatester asvar CTA
block is left as upstream (different rendering path).
@Waleed-Mujahid Waleed-Mujahid self-assigned this Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant