questionnaire-template bug

questionnaire-template bug

by Stanislav Shultsov -
Number of replies: 4

When we create new questionnaire by using questionnaire-template. Questionnaire-template has unicode-symbols in 'name' field in 'questionnaire_survey' table. And then the error of recording in DB has occured. We think that problem is located in survey_copy() function. It use the substr() function which corrupt the characters in myltibyte encodes.

We use a little hack: mb_substr($survey->name, 0, (64-10), "UTF-8") instead substr().

Average of ratings: -
In reply to Stanislav Shultsov

Re: questionnaire-template bug

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

1.- Which version of Moodle and Questionnaire are you using?

2.- Which language are you using? I suppose you are using Cyrillic characters.

3.- Please attach - as text - the exact complete name that you enter in your new questionnaire.

4.- Which error message do you get?

Joseph

In reply to Joseph Rézeau

Re: questionnaire-template bug

by Stanislav Shultsov -

1. Moodle 2.4.3 (Build: 20130318).
    mod_questionnaire 2.4.2(Build - 2013062000) for Moodle 2.4

2. All right, we use Russian language with cyrillic characters.

3. Анкета «ИОМ глазами студента» (also we attach - as text - in the file)

4. Some debug information from moodle:

Debug info:
Stack trace:
  • line 429 of \lib\dml\moodle_database.php: dml_write_exception thrown
  • line 1107 of \lib\dml\mysqli_native_moodle_database.php: call to moodle_database->query_end()
  • line 1149 of \lib\dml\mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->insert_record_raw()
  • line 997 of \mod\questionnaire\locallib.php: call to mysqli_native_moodle_database->insert_record()
  • line 146 of \mod\questionnaire\lib.php: call to questionnaire->survey_copy()
  • line 448 of \course\modedit.php: call to questionnaire_add_instance()

    -------------------------------------------------------------------------------

Variables in local scope (#6)

$error = 

string

'Incorrect string value: '\xC2_copy' for column 'name' at row 1' (length=62) 
$params =
array
  0 => 

string

 'Анкета «ИОМ глазами студента�_copy' (length=59)
  1 => 

string

 '9612' (length=4)
  2 => 

string

 'template' (length=8)
  3 => 

int

 0
  4 => 

string

 'Анкета «ИОМ глазами студента»' (length=55)
  5 => 

string

 '' (length=0)
  6 => 

string

 '' (length=0)
  7 => 

string

 '' (length=0)
  8 => 

string

 '' (length=0)
  9 => 

string

 '' (length=0)
  10 => 

string

 '' (length=0)
  11 => 

string

 '' (length=0)
$result = 

boolean

 false
$sql = 

string

 'INSERT INTO mdl_questionnaire_survey (name,owner,realm,status,title,email,subtitle,info,theme,thanks_page,thank_head,thank_body) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)' (length=160)
In reply to Stanislav Shultsov

Re: questionnaire-template bug

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Thanks for the detailed info. There is a very easy fix for that bug, use textlib function.

In Moodle 2.4.2, file questionnaire.class.php line 970, replace

$survey->name = substr($survey->name, 0, (64-10));

with

$survey->name = textlib::substr($survey->name, 0, (64-10));

I have opened issue CONTRIB-4398 in the tracker. Thanks for reporting this bug. Please try out my fix and confirm that it works for you.

Joseph

Average of ratings: Useful (1)