The registration link can fail if a user's name contains a diacritic

Bug #1026618 reported by Simon Story
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Mahara
Fix Released
Medium
Simon Story

Bug Description

Please note this only seems to effect PHP running on Windows, not Ubuntu.

In the following configuration:
Windows Server 2008 R2
IIS 7
Postgresql 9.1.4
PHP 5.3.13
Mahara 1.5.1

The registration link ("Hi Chéese, Thank you for registering an account on Mahara. Please follow this link to complete the signup process: ...") won't work if the user has a diacritic in their name.

Clicking the link results in "A nonrecoverable error occured. This probably means you have encountered a bug in the system"

The email address confirmation message ("Hi Chéese, Thank you for registering an account on Mahara. Please select the following link to confirm your email address. The ...") and the message sent to the administrator to approve the registration work perfectly.

Attached is a relevant snippet from the PHP error log.

Revision history for this message
Simon Story (simon-story) wrote :
description: updated
Revision history for this message
Simon Story (simon-story) wrote :

I see this is get_new_username() using substr in a non-utf8 safe way, I think I've fixed that. Something like:

index b90a9fc..72c0a83 100644
--- a/htdocs/lib/user.php
+++ b/htdocs/lib/user.php
@@ -1402,7 +1402,7 @@ function get_new_username($desired) {
     $taken = get_column_sql('
         SELECT LOWER(username) FROM {usr}
         WHERE username ' . db_ilike() . " ?",
- array(substr($desired, 0, $maxlen - 6) . '%'));
+ array(utf8_encode(substr(utf8_decode($desired), 0, $maxlen - 6) . '%')));
     if (!$taken) {
         return $desired;
     }

I think I've fixed that function, but then problem moves into create_user() :-/.

Wild speculation: I think the root of this problem is the Windows PHP binaries installed use plain libiconv 1.11 and on ubuntu php uses the bundled glibc iconv functions and things are behaving slightly differently.

tags: added: patch translations windows
Changed in mahara:
status: New → Triaged
importance: Undecided → Medium
Revision history for this message
Simon Story (simon-story) wrote :

Turns out that fixing get_new_username() was the best thing to do.

Attached is a patch for this bug to branch master.

I've tested it on:
Windows + IIS7 + PHP 5.3.13 + Postgres 8.3 (DB Running on Ubuntu 10.04)
Windows + IIS7 + PHP 5.3.13 + Postgres 9.1 (DB Running on Windows)
Ubuntu 12.04 + PHP 5.3.10 + Postgres 8.3 (DB Running on Ubuntu 10.04)

Basically the substr and strtolower operations on the user's name needed to use the mb_ style equivalents to not upset the DB.

But now this shows a new bug, you can't do the login with a username containing a diacritic on Windows. A quick test on Linux shows this works fine on version 1.5 and what is on branch master at the moment.

I imagine the problem with the login is similar.

Revision history for this message
Hugh Davenport (hugh-davenport) wrote :
Changed in mahara:
status: Triaged → In Progress
assignee: nobody → Simon Story (simon-story)
Changed in mahara:
milestone: none → 1.6.0
Revision history for this message
Mahara Bot (dev-mahara) wrote : A change has been merged

Reviewed: https://reviews.mahara.org/1448
Committed: http://gitorious.org/mahara/mahara/commit/d91b44b7efb9b7af4d11097c5edf1ea01b1dede8
Submitter: Hugh Davenport (<email address hidden>)
Branch: master

commit d91b44b7efb9b7af4d11097c5edf1ea01b1dede8
Author: Simon Story <email address hidden>
Date: Thu Jul 26 14:39:16 2012 +0100

    Use mb_ funcs on new usernames with diacritics. (Bug #1026618)

    Windows served Mahara has problems with this.

    Change-Id: I9872eecc9521d1c4061d88cded55a97d6eb8f195
    Signed-off-by: Simon Story <email address hidden>

Revision history for this message
Mahara Bot (dev-mahara) wrote :

Reviewed: https://reviews.mahara.org/1634
Committed: http://gitorious.org/mahara/mahara/commit/59f32c4195b98add8bb3921c905964b9b1c0f762
Submitter: Hugh Davenport (<email address hidden>)
Branch: 1.6_STABLE

commit 59f32c4195b98add8bb3921c905964b9b1c0f762
Author: Simon Story <email address hidden>
Date: Thu Jul 26 14:39:16 2012 +0100

    Use mb_ funcs on new usernames with diacritics. (Bug #1026618)

    Windows served Mahara has problems with this.

    Change-Id: I9872eecc9521d1c4061d88cded55a97d6eb8f195
    Signed-off-by: Simon Story <email address hidden>

Changed in mahara:
status: In Progress → Fix Committed
Revision history for this message
Hugh Davenport (hugh-davenport) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

 status fixreleased
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iJwEAQECAAYFAlCbHO8ACgkQuMoJ2LQ3zxH8TAP/YN4BiCJZsn5a899/0UzV31Qg
lM8LXAwZWa6zFv6t0BQUHCqe6eFK9wPp51qgCWWXjUZ3vvvVcsyeWp6626aBFKSU
pCQXI9E7huPw802nJQ9WcZXRBUmgw87ww72Tx4mybnu7SPSrkZgXdnPGSMwDs89N
oWvTpl7Xuac48e6p0lU=
=ouU+
-----END PGP SIGNATURE-----

Changed in mahara:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.