Author: kake Date: 2012-03-06 08:54:04 +0000 (Tue, 06 Mar 2012) New Revision: 1308
Modified: trunk/lib/OpenGuides/Template.pm trunk/t/19_autocreate.t Log: Made sure that categories with double spaces or newline in can't be created, as these are then undeletable with the web interface.
Modified: trunk/lib/OpenGuides/Template.pm =================================================================== --- trunk/lib/OpenGuides/Template.pm 2012-03-05 02:01:37 UTC (rev 1307) +++ trunk/lib/OpenGuides/Template.pm 2012-03-06 08:54:04 UTC (rev 1308) @@ -312,14 +312,15 @@ my $locales_text = $q->param('locales');
# Basic sanity-checking. Probably lives elsewhere. - $categories_text =~ s/</</g; - $categories_text =~ s/>/>/g; - $locales_text =~ s/</</g; - $locales_text =~ s/>/>/g; + foreach ( $categories_text, $locales_text ) { + s/</</g; + s/>/>/g; + }
- @catlist = sort grep { s/^\s+//; s/\s+$//; $_; } # trim lead/trail space + # Trim leading and trailing spaces, collapse internal whitespace. + @catlist = sort grep { s/^\s+//; s/\s+$//; s/\s+/ /g; $_; } split("\r\n", $categories_text); - @loclist = sort grep { s/^\s+//; s/\s+$//; $_; } # trim lead/trail space + @loclist = sort grep { s/^\s+//; s/\s+$//; s/\s+/ /g; $_; } split("\r\n", $locales_text); }
Modified: trunk/t/19_autocreate.t =================================================================== --- trunk/t/19_autocreate.t 2012-03-05 02:01:37 UTC (rev 1307) +++ trunk/t/19_autocreate.t 2012-03-06 08:54:04 UTC (rev 1308) @@ -1,5 +1,6 @@ use strict; use Cwd; +use Wiki::Toolkit::Plugin::Categoriser; use OpenGuides; use OpenGuides::Test; use Test::More; @@ -11,16 +12,58 @@ "DBD::SQLite could not be used - no database to test with. ($error)"; }
-plan tests => 4; +plan tests => 12;
my $config = OpenGuides::Test->make_basic_config; $config->custom_template_path( cwd . "/t/templates/" ); my $guide = OpenGuides->new( config => $config ); my $wiki = $guide->wiki; +my $categoriser = Wiki::Toolkit::Plugin::Categoriser->new; +$wiki->register_plugin( plugin => $categoriser );
# Clear out the database from any previous runs. OpenGuides::Test::refresh_db();
+# Check that unwelcome characters are stripped from autocreated cats/locales. +# Double spaces: +OpenGuides::Test->write_data( + guide => $guide, + node => "Arbat", + categories => "Delicious Russian Food", + return_output => 1, + ); + +ok( !$wiki->node_exists( "Category Delicious Russian Food" ), + "Categories with double spaces in are not auto-created." ); +ok( $wiki->node_exists( "Category Delicious Russian Food" ), + "...but the corresponding category with single spaces is." ); +ok ( !$categoriser->in_category( node => "Arbat", + category => "Delicious Russian Food" ), + "...and the new node is not in the double-spaced category." ); +ok ( $categoriser->in_category( node => "Arbat", + category => "Delicious Russian Food" ), + "...but it is in the single-spaced one." ); + +# Newlines: +OpenGuides::Test->write_data( + guide => $guide, + node => "Liaison", + categories => "Dim\nSum", + return_output => 1, + ); + +ok( !$wiki->node_exists( "Category Dim\nSum" ), + "Categories with newlines in are not auto-created." ); +ok( $wiki->node_exists( "Category Dim Sum" ), + "...but the corresponding category with single spaces is." ); +ok ( !$categoriser->in_category( node => "Liaison", + category => "Dim\nSum" ), + "...and the new node is not in the newlined category." ); +ok ( $categoriser->in_category( node => "Liaison", + category => "Dim Sum" ), + "...but it is in the single-spaced one." ); + + # Write a custom template to autofill content in autocreated nodes. eval { unlink cwd . "/t/templates/custom_autocreate_content.tt"; @@ -40,6 +83,7 @@ node => "Vivat Bacchus", categories => "Restaurants\r\nVegan-friendly", locales => "Farringdon", + return_output => 1, );
ok( $wiki->node_exists( "Category Vegan-Friendly" ), @@ -67,6 +111,7 @@ guide => $guide, node => "Bleeding Heart", categories => "Pubs", + return_output => 1, ); $content = $wiki->retrieve_node( "Category Pubs" ); $content =~ s/\s+$//s;
openguides-commits@lists.openguides.org