Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor noreplyemail language string #76

Merged
merged 2 commits into from
Nov 25, 2024

Conversation

djarran
Copy link
Contributor

@djarran djarran commented Nov 25, 2024

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

@djarran djarran self-assigned this Nov 25, 2024
@djarran djarran force-pushed the MOODLE_39_STABLE-template-string-use branch from 2753656 to 90e29f7 Compare November 25, 2024 05:40
@bwalkerl bwalkerl merged commit 5908ec1 into MOODLE_39_STABLE Nov 25, 2024
67 of 70 checks passed
@bwalkerl bwalkerl deleted the MOODLE_39_STABLE-template-string-use branch November 25, 2024 06:52
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.

2 participants