[cgi-wiki-dev] UTF-8, Node names, and recent changes
Tom Insam
cgi-wiki-dev@earth.li
Thu, 16 Dec 2004 10:14:50 +0000
--Apple-Mail-2-330839372
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
format=flowed
On Dec 16, 2004, at 8:52, Kake L Pugh wrote:
> On Wed 15 Dec 2004, Tom Insam <tom@jerakeen.org> wrote:
>> I found a bug with the CGI::Wiki utf8 support - node names in the
>> recent changes list weren't getting handled as utf-8 properly. This
>> fixes it.
>
> Could you send a test, please?
Ok, this is a test that'll test the other utf-8 functionality as well
as the thing I just added. I've had to mess with testlib a little to
let me pass store creation params through, to set the utf8 flag, but
it's quite clean otherwise.
Fixes a bug, too - if you passed a dbh to the store, it ignored the
charset setting. Yay, tests.
--Apple-Mail-2-330839372
Content-Transfer-Encoding: 7bit
Content-Type: application/octet-stream;
x-unix-mode=0644;
name="test_utf8.diff"
Content-Disposition: attachment;
filename=test_utf8.diff
Index: t/160_utf8.t
===================================================================
--- t/160_utf8.t (revision 0)
+++ t/160_utf8.t (revision 0)
@@ -0,0 +1,35 @@
+use strict;
+use CGI::Wiki;
+use CGI::Wiki::TestLib;
+use Test::More;
+
+if ( scalar @CGI::Wiki::TestLib::wiki_info == 0) {
+ plan skip_all => "no backends configured";
+} elsif ( eval "use Encode" && !$@ ) {
+ plan skip_all => "No Encode support";
+} else {
+ plan tests => ( 6 * scalar @CGI::Wiki::TestLib::wiki_info );
+}
+
+my $iterator = CGI::Wiki::TestLib->new_wiki_maker;
+
+while ( my $wiki = $iterator->new_wiki( { charset => "utf8" } ) ) {
+ # Test a simple write and retrieve.
+ ok( $wiki->write_node("A Nod\x{e9}", "Here's a nasty character: \x{2264}"),
+ "write_node can create a node with nasty title" );
+
+ is( $wiki->retrieve_node("A Nod\x{e9}"), "Here's a nasty character: \x{2264}",
+ "retrieve_node can retrieve it" );
+
+ # Test ->node_exists.
+ ok( $wiki->node_exists("A Nod\x{e9}"),
+ "node_exists returns true for an existing node" );
+ ok( ! $wiki->node_exists("This Is A Nonexistent Node"),
+ "...and false for a nonexistent one" );
+
+ ok( my @recent = $wiki->list_recent_changes( days => 7 ),
+ "got recent changes" );
+ is( $recent[0]->{name}, "A Nod\x{e9}",
+ "recent change is the right node" );
+
+}
Index: lib/CGI/Wiki/TestLib.pm
===================================================================
--- lib/CGI/Wiki/TestLib.pm (revision 1400)
+++ lib/CGI/Wiki/TestLib.pm (working copy)
@@ -197,12 +197,16 @@
sub new_wiki {
my $self = shift;
+ my $store_extra = shift; # extra things to put into datastore_info
+
return undef if $$self > $#wiki_info;
my $details = $wiki_info[$$self];
my %wiki_config;
# Set up and clear datastore.
my %datastore_info = %{ $details->{datastore_info } };
+ $datastore_info{params}{$_} = $store_extra->{$_} for (keys(%$store_extra));
+
my $setup_class = $datastore_info{setup_class};
eval "require $setup_class";
{
Index: lib/CGI/Wiki/Store/Database.pm
===================================================================
--- lib/CGI/Wiki/Store/Database.pm (revision 1402)
+++ lib/CGI/Wiki/Store/Database.pm (working copy)
@@ -91,6 +91,8 @@
sub _init {
my ($self, %args) = @_;
+ $self->{_charset} = $args{charset} || "iso-8859-1";
+
if ( $args{dbh} ) {
$self->{_dbh} = $args{dbh};
$self->{_external_dbh} = 1; # don't disconnect at DESTROY time
@@ -100,8 +102,7 @@
$self->{_dbuser} = $args{dbuser} || "";
$self->{_dbpass} = $args{dbpass} || "";
$self->{_dbhost} = $args{dbhost} || "";
- $self->{_charset} = $args{charset} || "iso-8859-1";
-
+
# Connect to database and store the database handle.
my ($dbname, $dbuser, $dbpass, $dbhost) =
@$self{qw(_dbname _dbuser _dbpass _dbhost)};
--Apple-Mail-2-330839372--