trampgeek / moodle-qtype_coderunner

CodeRunner: A moodle quiz question type that runs student-submitted program code in a sandbox to check if it satisfies a given set of tests.
GNU General Public License v2.0
207 stars 120 forks source link

Add validation: Sandbox lang cannot be empty when creating a prototype #195

Closed AnupamaSarjoshi closed 7 months ago

AnupamaSarjoshi commented 8 months ago

Hi Richard,

We are seeing the following deprecation warnings on some of our questions. Warning is in the function answerbox_attributes, when $currentlanguage is null anducwords doesn't accept it.

Deprecated: ucwords(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/moodle/question/type/coderunner/renderer.php on line 749

Have noticed that the questions with these warnings are all using user defined prototype templates (which seems to have been deleted on our systems). But the problem here is when I looked into the database table question_coderunner_options, the language for these user defined prototypes is set to null.

And I suppose, we should never have a user defined prototype template with empty sandbox language. Hence adding a validation to the sandbox language would prevent those issues. Though adding ucwords($currentlanguage ?? ''); would fix the existing issues as well, I was not sure if that is the right thing to do and thought would be good to confirm before doing that change.

Could you please have a look and suggest if I have understood it correctly and the fix is right?

I was able to reproduce this issue with the following steps:

  1. Create an user defined prototype template.
  2. Edit the prototype template. Navigate to 'Advanced customisation'.
  3. Set 'Sandbox language' to ''
  4. Save the prototype and preview.
  5. Notice that the above warning message is displayed.

Thanks, Anupama

trampgeek commented 7 months ago

Thanks Anupama. I'm not sure how an empty sandbox languages comes about, unless by deliberately setting it to empty. It should be filled in from the originating question type before customise was clicked. But your changes are all perfectly safe and do protect against someone deliberately or inadvertently clearing that field.