Short answer questions are ignoring case sensitivity option with non-ASCII characters

Short answer questions are ignoring case sensitivity option with non-ASCII characters

by Daniel Pospisil -
Number of replies: 11

Hi, I am running moodle version 1.9.4 and I am trying to create a quiz where one of my questions is a short answer one. The right answer to the question is this sitrng: "ITÁLIE" but some students may enter "Itálie" (word for Italy) and when I select the option "No, case is unimportant" it works OK (strings like "itÁlie are marked correct) until somebody enters a string with "á" then the answer is marked incorrect.

But next strange thing is, when I do a new installation on my computer, everything is working correctly, even when I import the database from my server > so all setting are the same.

PS: when I do an upgrade I delete the old moodle directory and upload a new one, so all files should be in the 1.9.4 version.

I hope somebody knows the answer.

Average of ratings: -
In reply to Daniel Pospisil

Re: Short answer questions are ignoring case sensitivity option with non-ASCII characters

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
It is strange that it works on one computer, but not another. Obviously, we need to know about the two computers. Which operating system? Which PHP version, etc. In particular, what is different between the two machines.

Until we have a solution, as a workaround you can create the question with two correct answers, ITÁLIE and ITáLIE, both worth 100%.
In reply to Tim Hunt

Re: Short answer questions are ignoring case sensitivity option with non-ASCII characters

by Daniel Pospisil -

So the server (shared environment) has:

OS: CentOS, PHP: 5.1.6, Apache: 2.0.63, MySQL: 5.0.68

My Computer has:

OS: Windows Vista Home Premium, PHP: 5.2.6, Apache: 2.2.9,  MySQL: 5.0.67

The solution with entering both lower and upper case answer works (I have it like that right now...)

In reply to Daniel Pospisil

Re: Short answer questions are ignoring case sensitivity option with non-ASCII characters

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
To make this easier to test, I have just put the problem case into the unit tests for this question type in both the 1.9 and 2.0 branches. So, after you next update, if you go to the URL .../admin/report/unittest/index.php?path=question%2Ftype%2Fshortanswer on your server, it should run the test for this question type, and I would expect you to see one test failure when you do that on your shared environment.

Note: it is normally a bad idea to run the unit tests on a production server, some of them do risky things. However the tests for this question type are safe.

Naturally, the test passes on my computer. (Ubuntu linux, PHP 5.2.8, Apache 2.x).

Of course, having the test only narrows down the problem by focussing on the 'compare_string_with_wildcard' without involving all the rest of the quiz code. It is not very helpful in fixing the problem. It would be useful to know if anyone else can make this test fail, and if so, one

In reply to Tim Hunt

Re: Short answer questions are ignoring case sensitivity option with non-ASCII characters

by Daniel Pospisil -

Where can I find those updated files? I wanted to update mine to run the test but http://cvs.moodle.org/moodle/admin/report/unittest/ files there are little old...

In reply to Daniel Pospisil

Re: Short answer questions are ignoring case sensitivity option with non-ASCII characters

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Sorry, I should have explained better.

the admin/report/unittest/ is simply the framework that finds all the unit tests you ask it to run, and runs them.

The actual unit tests live next to the code they test. Any file called text....php in a folder called simpletest is assumed to contain unit tests. So the actual file you need to update is

question/type/shortanswer/simpletest/testquestiontype.php

And the URL I gave you to run the unit tests only runs that one file.
In reply to Tim Hunt

Re: Short answer questions are ignoring case sensitivity option with non-ASCII characters

by Daniel Pospisil -

Ok, exactly how you expected:

Fail: question/type/shortanswer/simpletest/testquestiontype.php question_shortanswer_qtype_test test_compare_string_with_wildcard
at [*server_path*/moodle/question/type/shortanswer/simpletest/testquestiontype.php line 71]
1/1 test cases complete: 61 passes, 1 fails and 0 exceptions.
In reply to Daniel Pospisil

Re: Short answer questions are ignoring case sensitivity option with non-ASCII characters

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Well, this is definitely a bug, so I have created a tracker issue for it: MDL-18802 (using my admin powers to make it look like you reported it wink I hope that is OK.)

The key part of the compare_string_with_wildcard function uses the PHP's pcre library, and to make further progress, I think we need some more data points about when and where it fails.
In reply to Tim Hunt

Re: Short answer questions are ignoring case sensitivity option with non-ASCII characters

by Daniel Pospisil -

Thats completely fine smile

I also checked my version of PCRE and this is what the server has:

PCRE (Perl Compatible Regular Expressions) Support  enabled 
PCRE Library Version  4.5 01-December-2003 

I think it is really an outdated version - couldn't that be the source of the problem?

In reply to Daniel Pospisil

Re: Short answer questions are ignoring case sensitivity option with non-ASCII characters

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Wow! that is ancient.

I would not be at all surprised if that is the cause. The PCRE library change log is at http://www.pcre.org/changelog.txt. I can't be bothered to read it all now to see whether there was a bug fix between 4.5 and now that fixed this.

Are you able to get that library updated on the server?
In reply to Tim Hunt

Re: Short answer questions are ignoring case sensitivity option with non-ASCII characters

by Daniel Pospisil -

Well I will try to get it updated - but I know it is sometimes really difficult to make those people who are running that shared environment actually do something...

So I guess the problem is solved for now... Thanks for helping me Tim smile

In reply to Tim Hunt

Re: Short answer questions are ignoring case sensitivity option with non-ASCII characters

by Daniel Pospisil -
Finally, they updated PCRE library to the newest version a the problem is gone... Thank you Tim smile