Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

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

Merged
merged 1 commit into from
Feb 11, 2024

Conversation

AnupamaSarjoshi
Copy link
Contributor

@AnupamaSarjoshi AnupamaSarjoshi commented Feb 6, 2024

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 and ucwords 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 trampgeek merged commit 22ba2ab into trampgeek:master Feb 11, 2024
@trampgeek
Copy link
Owner

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.

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