catalyst / moodle-tool_emailutils

2 stars 2 forks source link

Refactor noreplyemail language string #76

Closed djarran closed 1 week ago

djarran commented 1 week ago

Description: This PR refactors the noreplyemail language string. This was done to resolve unit test failures in Totara 17:

Problem

test_no_exploitable_string_helper_uses server/lib/tests/mustache_str_helper_test.php

1) mustache_string_helper_testcase::test_no_exploitable_string_helper_uses
Templates containing variables in string helpers.
 * /admin/tool/emailutils/templates/postmaster.mustache :: 1

/var/www/site/server/lib/tests/mustache_str_helper_test.php:409
/var/www/site/server/lib/phpunit/classes/testcase.php:114
phpvfscomposer:///var/www/site/test/phpunit/vendor/phpunit/phpunit/phpunit:97

Occurring here: https://github.com/catalyst/moodle-tool_emailutils/blob/MOODLE_39_STABLE/templates/postmaster.mustache#L41

Looks like Totara doesn't like it when language string templates/helpers are used like here:

<p>{{#str}} noreplyemail, tool_emailutils, {{ noreply }} {{/str}}</p>

They have a whitelist that can be used to skip certain files, but this would require a core hack:

        $whitelist = new path_whitelist([
            $CFG->dirroot . '/lib/templates/test.mustache', // A mustache test file. Must not contain anything exploitable.
            $CFG->dirroot . '/totara/core/templates/progressbar.mustache', // Deprecated since Totara 12.
        ]); // Totara: path_whitelist

Solution

Use the code HTML element in the Mustache template instead of the language string. This does not change the styling or structure of the template when rendered. This was tested using the template library.

This PR also fixes the example context in the template by removing trailing commas and changing vendors to vendor in the vendorinfo object. This can be tested in admin/tool/templatelibrary/index.php?component=&search=emailutils