Issue Details (XML | Word | Printable)

Key: MDL-3381
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Critical Critical
Assignee: Mathieu Petit-Clair
Reporter: Imported
Votes: 2
Watchers: 3
Operations

Add/Edit UI Mockup to this issue
If you were logged in you would be able to see more operations.
Moodle

search gives empty page --> ctype_spacer()

Created: 01/Jun/05 01:50 AM   Updated: 02/May/08 06:20 AM
Return to search
Component/s: General, Installation, Lib
Affects Version/s: 1.5, 1.9
Fix Version/s: 1.8.6, 1.9.1

File Attachments: 1. Text File patch-3381_ctype.txt (3 kB)

Environment: Linux
Issue Links:
Duplicate
 

Database: MySQL
Participants: Chris Bandy, Dirk Weller, Eloy Lafuente (stronk7), Imported, Martin Dougiamas and Mathieu Petit-Clair
Security Level: None
QA Assignee: Eloy Lafuente (stronk7)
Resolved date: 24/Apr/08
Affected Branches: MOODLE_15_STABLE, MOODLE_19_STABLE
Fixed Branches: MOODLE_18_STABLE, MOODLE_19_STABLE


 Description  « Hide
Trying to do a search in forums or on the whole site results in an empty page when using f.i. a word like color.



Using as search string +color all goes well.



Log error message of apache:

Call to undefined function ctype_space() in ../lib/searchlib.php on line 297



Moodle version: 2005052300 1.5dev

 All   Comments   Change History   Version Control      Sort Order: Ascending order - Click to sort in descending order
Martin Dougiamas added a comment - 05/Jun/05 05:20 PM
From Herbert Keijers (herbert.keijers at vanhorne.nl) Saturday, 4 June 2005, 05:32 PM:

Forgot to mention php version 4.1.2

From Herbert Keijers (herbert.keijers at vanhorne.nl) Sunday, 5 June 2005, 05:20 PM:

Some (elder) php4 versions do not support the ctype functions.

So it is not a bug.

See my postings in : http://moodle.org/mod/forum/discuss.php?d=24762


Michael Blake made changes - 21/Aug/06 03:56 PM
Field Original Value New Value
Assignee Martin Dougiamas [ martindougiamas ] Martin Dougiamas [ dougiamas ]
Martin Dougiamas made changes - 23/Aug/06 11:48 PM
Status In Progress [ 3 ] Open [ 1 ]
Michael Blake made changes - 19/Sep/06 04:08 PM
Assignee Martin Dougiamas [ dougiamas ] Vy-Shane Sin Fat [ vyshane ]
Martin Dougiamas added a comment - 21/Feb/07 09:22 AM
Assigning to me temporarily because Vy-Shane no longer works for Moodle HQ.

Martin Dougiamas made changes - 21/Feb/07 09:22 AM
Assignee Vy-Shane Sin Fat [ vyshane ] Martin Dougiamas [ dougiamas ]
Chris Bandy added a comment - 28/Jul/07 12:59 AM - edited
We have the same issue with Moodle 1.6.5+ (2006050550) on PHP 5.1.2, Postgresql 8.1.4, and openSUSE 10.1.

"PHP Fatal error: Call to undefined function ctype_space() in .../moodle/lib/searchlib.php on line 296"

This function requires the ctype extension for PHP:
extension_loaded('ctype');


Dirk Weller added a comment - 22/Oct/07 04:33 PM
We have the same issue with Moodle 1.8.2 and 1.8.3 on Mysql 5.0.26 Apache 2.2.0 PHP 5.1.2 Suhosin Patch 0.9.6 and Zend Engine v2.1.0 - SuSE 10.1

Dirk Weller added a comment - 22/Oct/07 06:21 PM
Issue closed for SuSE 10.1 / See http://moodle.org/mod/forum/discuss.php?d=80814 --> ctype is an extra php module for SuSE and needs to be installed

Chris Bandy added a comment - 22/Oct/07 07:41 PM - edited
As of Moodle 1.8.3, ctype functions are still used in:

course/lib.php
lib/adodb/adodb-datadict.inc.php
lib/searchlib.php
search/Zend/Search/Lucene/Analysis/Analyzer/Common/Text.php
search/Zend/Search/Lucene/Search/QueryTokenizer.php

The ctype module is optional[1] in PHP, and other distributions (Gentoo for one) optionally include it.
The resolution to this this long-standing bug is to add ctype as a PHP requirement in environment.xml

Please vote for this issue.

[1] http://www.php.net/manual/en/ref.ctype.php#ctype.installation


Mathieu Petit-Clair added a comment - 10/Dec/07 02:00 PM
This problem (ctype_space in searchlib) will still exists in Moodle 1.9, and there's another call (ctype_alpha in course/lib.php) that will be a problem for people without ctype.

Possibilities :

  • make ctype an official requirement for Moodle;
  • change the ctype_space() call to a trim() (seems to be equivalent) and include a "western-equivalent" function to ctype_alpha (see http://au.php.net/manual/en/function.ctype-alpha.php#75854 for the code, which is probably a problem for scripts not using western characters);
  • find a way to do without ctype functions.

Mathieu Petit-Clair added a comment - 10/Dec/07 02:54 PM
Here's a start of a patch.. This needs to be changed depending on whether ctype is required for moodle or not.

Mathieu Petit-Clair made changes - 10/Dec/07 02:54 PM
Attachment patch-3381_ctype.txt [ 12601 ]
Chris Bandy made changes - 16/Apr/08 03:19 AM
Link This issue is a clone of MDL-14375 [ MDL-14375 ]
Eloy Lafuente (stronk7) added a comment - 16/Apr/08 09:05 AM
Hi, just saw this. Two comments:

1) course.lib use looks really trivial, It's being used to check if the fist letter is alpha (and the list of log actions are simple english words). Can be matched with regexp instead.
2) searchlib.php use of ctype_space can be also safely replaced by one simple trim() === ''

With this... all Moodle 1.9 would be ctype_* free (unless you enable HTMLPurifier or Global search). Perhaps it could be added as OPTIONAL.

For 2.0 we must REQUIRE ctype IMO, mainly because HTMLPurifier has high probabilities to become the standard filter and we cannot patch it locally.

Ciao


Eloy Lafuente (stronk7) made changes - 16/Apr/08 09:07 AM
Link This issue is duplicated by MDL-14375 [ MDL-14375 ]
Eloy Lafuente (stronk7) made changes - 16/Apr/08 09:09 AM
Link This issue is a clone of MDL-14375 [ MDL-14375 ]
Eloy Lafuente (stronk7) added a comment - 16/Apr/08 09:11 AM
Raising this to critical. Should be fixed ASAP IMO. Assigning to Mathieu.

Eloy Lafuente (stronk7) made changes - 16/Apr/08 09:11 AM
Fix Version/s 1.9.1 [ 10240 ]
Affects Version/s 1.9 [ 10190 ]
Component/s General [ 10049 ]
Component/s Lib [ 10096 ]
Component/s Forum [ 10051 ]
Assignee Martin Dougiamas [ dougiamas ] Mathieu Petit-Clair [ scyrma ]
Priority Trivial [ 5 ] Critical [ 2 ]
Component/s Installation [ 10069 ]
Mathieu Petit-Clair added a comment - 16/Apr/08 11:31 AM
Adding Martín Langhoff to this issue, since he's to author of the code in course/lib.php. Martín : is it necessary to use ctype_alpha on line 120? Can $modaction contain non-latin characters?

Mathieu Petit-Clair committed 1 file to 'Moodle CVS' on branch 'MOODLE_19_STABLE' - 16/Apr/08 11:35 AM
MDL-3381 - changing call to ctype_space to remove dependency on ctype
MODIFY lib/searchlib.php   Rev. 1.13.6.1    (+2 -2 lines)
Mathieu Petit-Clair committed 1 file to 'Moodle CVS' - 16/Apr/08 11:37 AM
MDL-3381 - changing call to ctype_space to remove dependency on ctype (merge from 1.9)
MODIFY lib/searchlib.php   Rev. 1.14    (+2 -2 lines)
Mathieu Petit-Clair added a comment - 16/Apr/08 11:41 AM
I modified the call in searchlib.php.

Eloy, should I commit the patch (attached to this issue) to 1.9? If we require ctype for 2.0, I will modify the patch for this requirement in head.


Eloy Lafuente (stronk7) added a comment - 20/Apr/08 05:41 PM
Hi Mathieu,

I think your patch about doing ctype optional in 1.9 is ok. So +1 for that, with 3 comments:

1) It should be applied from 17_STABLE to HEAD (that way people running older Moodle versions will know about that recommendation, without downloading xml).
2) If you add new strings that are going to be showed by the installer... you need to add them to all those branches too (en_utf8) and, important, add them to install/stringnames.txt . That way, nightly package generators are able to put them in the proper installer lang files.
3) Perhaps I'd delay this until next HQ chat to see if definitively we are going to make ctype mandatory for 2.0. To send the whole solution in the same commit.

About your $modaction question for ML... I think I was looking for that when I wrote my previous comment here and I think all I saw were English tokens. So I really think it could be safe to change it. In fact, hehe, exactly in the previous line of the ctype_alpha() call, there is one $firstletter = substr($modaction, 0, 1); and that breaks UTF-8 (non-ascii) strings, so yes, I guess it only can contain english (ascii) letters.

Ciao


Martin Dougiamas added a comment - 21/Apr/08 04:16 PM
My +1 for optional in 1.9 and required in 2.0.

Mathieu Petit-Clair added a comment - 21/Apr/08 04:24 PM
Ok, as discussed in meeting : ctype recommended until 1.9, required from 2.0. Patches coming in the next few days.

Mathieu Petit-Clair added a comment - 24/Apr/08 10:51 AM
I just had a look on php.net and ctype is enabled by default since php 4.2.0, and builtin since php 4.3.0. Anybody having this problem is on a seriously old host. I'm committing this patch, since I'm done .. but really, this shouldn't be a problem anymore (Moodle won't even run on a php that old!). See (as said above) http://au.php.net/manual/en/ctype.installation.php for details.

Mathieu Petit-Clair committed 5 files to 'Moodle CVS' on branch 'MOODLE_19_STABLE' - 24/Apr/08 11:01 AM
MDL-3381 - Remove all remaining core calls to ctype_* functions in 1.9, and make ctype required for 2.0.
MODIFY lang/en_utf8/admin.php   Rev. 1.154.2.40    (+2 -0 lines)
MODIFY admin/environment.xml   Rev. 1.24.2.4    (+10 -0 lines)
MODIFY install/lang/en_utf8/installer.php   Rev. 1.19.2.8    (+2 -0 lines)
MODIFY course/lib.php   Rev. 1.538.2.35    (+3 -3 lines)
MODIFY install/stringnames.txt   Rev. 1.3.2.5    (+2 -0 lines)
Mathieu Petit-Clair committed 5 files to 'Moodle CVS' - 24/Apr/08 11:07 AM
MDL-3381 - Remove all remaining core calls to ctype_* functions in 1.9, and make ctype required for 2.0. (merge from 1.9)
MODIFY course/lib.php   Rev. 1.578    (+3 -3 lines)
MODIFY install/stringnames.txt   Rev. 1.10    (+2 -0 lines)
MODIFY install/lang/en_utf8/installer.php   Rev. 1.28    (+2 -0 lines)
MODIFY lang/en_utf8/admin.php   Rev. 1.193    (+2 -0 lines)
MODIFY admin/environment.xml   Rev. 1.28    (+10 -0 lines)
Mathieu Petit-Clair committed 1 file to 'Moodle CVS' - 24/Apr/08 11:24 AM
MDL-3381 - Reverse broken commit
MODIFY course/lib.php   Rev. 1.579    (+3 -3 lines)
Mathieu Petit-Clair added a comment - 24/Apr/08 11:25 AM
Fixed in MOODLE_19_STABLE, merged in HEAD. Should the ctype_* removals be backported?

Mathieu Petit-Clair made changes - 24/Apr/08 11:25 AM
Status Open [ 1 ] Resolved [ 5 ]
Resolution Fixed [ 1 ]
Mathieu Petit-Clair committed 1 file to 'Moodle CVS' - 24/Apr/08 02:40 PM
MDL-3381 - Prevent the un-necessary calls to ctype_alpha.
MODIFY course/lib.php   Rev. 1.580    (+3 -3 lines)
Mitsuhiro Yoshida committed 1 file to 'Lang CVS' - 25/Apr/08 02:02 AM
Translated new strings for admin MDL-3381.
MODIFY ja_utf8/admin.php   Rev. 1.263    (+3 -1 lines)
martignoni committed 1 file to 'Lang CVS' - 28/Apr/08 02:52 PM
MDL-3381, two new strings
MODIFY fr_utf8/admin.php   Rev. 1.248    (+3 -1 lines)
Eloy Lafuente (stronk7) added a comment - 29/Apr/08 08:31 AM
Hi Mathieu,

I really think patches are ok. Anyway, I'd backport them to 1.8 as they are trivial and can make life better for some sites.

FYC... with MD. feel free to close this definitively once backported (or not backported).

Only one small comment... install/lang/xxx file must not be edited by us at all. All we need to do it to add them to the install/stringnames.txt file and then one nightly process will build automatically the install/lang/xxx files.

Ciao


Eloy Lafuente (stronk7) made changes - 29/Apr/08 08:31 AM
Fix Version/s 1.8.6 [ 10270 ]
QA Assignee stronk7
Resolution Fixed [ 1 ]
Status Resolved [ 5 ] Reopened [ 4 ]
Mathieu Petit-Clair committed 4 files to 'Moodle CVS' on branch 'MOODLE_18_STABLE' - 01/May/08 04:07 PM
MDL-3381: Remove all remaining core calls to ctype_* functions and make ctype a recommended optional library. (backport from 1.9)
MODIFY course/lib.php   Rev. 1.484.2.32    (+3 -3 lines)
MODIFY lang/en_utf8/admin.php   Rev. 1.103.2.22    (+3 -1 lines)
MODIFY install/lang/en_utf8/installer.php   Rev. 1.13.2.9    (+2 -0 lines)
MODIFY admin/environment.xml   Rev. 1.18.2.5    (+15 -0 lines)
Mathieu Petit-Clair committed 1 file to 'Moodle CVS' on branch 'MOODLE_19_STABLE' - 01/May/08 04:10 PM
MDL-3381: keeping environment.xml in sync (from 1.8)
MODIFY admin/environment.xml   Rev. 1.24.2.5    (+5 -0 lines)
Mathieu Petit-Clair committed 1 file to 'Moodle CVS' - 01/May/08 04:10 PM
MDL-3381: keeping environement.xml in sync (from 1.8)
MODIFY admin/environment.xml   Rev. 1.29    (+5 -0 lines)
Mathieu Petit-Clair added a comment - 01/May/08 04:12 PM
Backported to 1.8. Eloy: it's not clear to me if /admin/environment.xml must be the same over all versions, but I did make the same changes in 1.8, 1.9 and head. Should this file be the same in 16 and 1.7?

Mathieu Petit-Clair made changes - 01/May/08 04:12 PM
Status Reopened [ 4 ] Closed [ 6 ]
Resolution Fixed [ 1 ]
Eloy Lafuente (stronk7) added a comment - 02/May/08 06:20 AM
Well, really it shouldn't be necessary as long as the xml file can be updated online from download.moodle.org.

I really think in this case it's enough to backport up to 1.8, because when the ctype is going to be a requirement is 2.0, and 2.0 requires 1.9 to be installed so everybody will have that info.

So, I think this is ok as is now. Thanks!