Item14199: Registration confirmation process corrupts utf-8 wiki names.
Priority: Urgent
Current State: Closed
Released In: 2.1.3
Target Release: patch
The registration_approvals file is dumped with incorrect encoding.
Register user
SteveKrüger with confirmation enabled. The confirmation file is created as:
# Verification code
$data = {
'LastName' => "Kr\x{fc}ger",
'LoginName' => "SteveKr\x{fc}ger",
'FirstName' => 'Steve',
'FirstLastName' => "Steve Kr\x{fc}ger",
'Password' => 'asdfasdf',
'form' => undef,
'VerificationCode' => "SteveKr\x{fc}ger.71428538",
'Email' =>
'WikiName' => "SteveKr\x{fc}ger",
'Name' => "Steve Kr\x{fc}ger",
'Confirm' => 'asdfasdf',
'webName' => 'Usersweb',
'templatetopic' => 'NewUserTemplate'
};
$form = [
{
'required' => '1',
'name' => 'FirstName',
'value' => 'Steve'
},
{
'required' => '1',
'value' => "Kr\x{fc}ger",
'name' => 'LastName'
},
{
'required' => '1',
'name' => 'WikiName',
'value' => "SteveKr\x{fc}ger"
},
Note the \x{fc} encoding of the ü. This results in a cUID of author="StevenKr_fcger". If the same user registers with confirmation disabled, the cUID becomes author="StefanKr_c3_bcger". So the round-trip through the confirmation process corrupts the cUID.
--
GeorgeClark - 12 Oct 2016
This patch (revision 2) does seem to fix it.
diff --git a/UnitTestContrib/test/unit/RegisterTests.pm b/UnitTestContrib/test/unit/RegisterTests.pm
index 9192fb4..47431f0 100644
--- a/UnitTestContrib/test/unit/RegisterTests.pm
+++ b/UnitTestContrib/test/unit/RegisterTests.pm
@@ -1879,9 +1879,12 @@ sub verify_UnregisteredUser {
};
my $file = Foswiki::UI::Register::_codeFile( $regSave->{VerificationCode} );
- $this->assert( open( my $F, '>', $file ) );
- print $F Data::Dumper->Dump( [ $regSave, undef ], [ 'data', 'form' ] );
- $this->assert( close $F );
+ use Storable;
+ store( $regSave, $file );
+
+ #$this->assert( open( my $F, '>', $file ) );
+ #print $F Data::Dumper->Dump( [ $regSave, undef ], [ 'data', 'form' ] );
+ #$this->assert( close $F );
my $result2 =
Foswiki::UI::Register::_loadPendingRegistration( $this->{session},
diff --git a/core/lib/Foswiki/UI/Register.pm b/core/lib/Foswiki/UI/Register.pm
index d301a1c..d6c0ac7 100755
--- a/core/lib/Foswiki/UI/Register.pm
+++ b/core/lib/Foswiki/UI/Register.pm
@@ -14,6 +14,7 @@ use strict;
use warnings;
use Assert;
use Error qw( :try );
+use Storable;
use Foswiki ();
use Foswiki::LoginManager ();
@@ -679,22 +680,8 @@ sub _requireConfirmation {
# SMELL: used for Register unit tests
$session->{DebugVerificationCode} = $data->{"${type}Code"};
- require Data::Dumper;
-
my $file = _codeFile( $data->{"${type}Code"} );
- my $F;
- open( $F, '>', $file )
- or throw Error::Simple( 'Failed to open file: ' . $! );
- print $F "# $type code\n";
-
- # SMELL: wierd jiggery-pokery required, otherwise Data::Dumper screws
- # up the form fields when it saves. Perl bug? Probably to do with
- # chucking around arrays, instead of references to them.
- my $form = $data->{form};
- $data->{form} = undef;
- print $F Data::Dumper->Dump( [ $data, $form ], [ 'data', 'form' ] );
- $data->{form} = $form;
- close($F);
+ store( $data, $file );
$session->logger->log(
{
@@ -2051,15 +2038,19 @@ sub _loadPendingRegistration {
);
}
- $data = undef;
- $form = undef;
- do $file;
- $data->{form} = $form if $form;
- throw Foswiki::OopsException(
- 'register',
- def => 'bad_ver_code',
- params => [ $code, 'Bad activation code' ]
- ) if $!;
+ try {
+ $data = retrieve($file);
+ }
+ catch Error with {
+ my $e = shift;
+ require Data::Dumper;
+ print STDERR Data::Dumper::Dumper( \$e );
+ throw Foswiki::OopsException(
+ 'register',
+ def => 'internal_error',
+ params => [ $code, 'Retrieve of stored registration failed' ]
+ );
+ };
return $data;
}
@@ -2165,8 +2156,7 @@ sub _checkPendingRegistrations {
}
if ($check) {
local $data;
- local $form;
- eval 'do $regFile';
+ $data = retrieve($regFile);
next unless defined $data;
push @pending, $data->{WikiName} . '(pending)'
if ( $check eq $data->{Email} );
diff --git a/core/templates/registermessages.tmpl b/core/templates/registermessages.tmpl
index 7e6c212..fcd9943 100644
--- a/core/templates/registermessages.tmpl
+++ b/core/templates/registermessages.tmpl
@@ -87,6 +87,13 @@
%MAKETEXT{"Please contact [_1] if you have any questions." args="<a href='mailto:%WIKIWEBMASTER%'>%WIKIWEBMASTER%</a>"}%
%TMPL:END%
%{==============================================================================}%
+%TMPL:DEF{"internal_error"}%
+---+++ %MAKETEXT{"Activation Failed"}%
+%MAKETEXT{"Activation for code [_1] failed with an internal error." args="'<code>%PARAM1%</code>'"}% %PARAM2%
+
+%MAKETEXT{"This is an internal error. You can try to register again, or contact [_1] to report the error." args="<a href='mailto:%WIKIWEBMASTER%'>%WIKIWEBMASTER%</a>"}%
+%TMPL:END%
+%{==============================================================================}%
%TMPL:DEF{"registration_mail_failed"}%
---+++ %MAKETEXT{"Error registering new user"}%
--
GeorgeClark - 12 Oct 2016