Changeset 592


Ignore:
Timestamp:
Dec 15, 2004, 2:18:35 PM (17 years ago)
Author:
kake
Message:

Fixed bug that allowed autocreation of locales and categories with trailing spaces in the name.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Changes

    r591 r592  
    77        Fix bug with diff display on nodes containing macros.
    88        Fixed distance search paging bug.
     9        Fixed bug that allowed autocreation of locales and categories with
     10          trailing spaces in the name.
    911       
    10120.45    1 December 2004
  • trunk/lib/OpenGuides/Template.pm

    r591 r592  
    246246        my $categories_text = $q->param('categories');
    247247        my $locales_text    = $q->param('locales');
    248         @catlist = sort split("\r\n", $categories_text);
    249         @loclist = sort split("\r\n", $locales_text);
     248        @catlist = sort map { s/^\s+//; s/\s+$//; $_; } # trim lead/trail space
     249                        split("\r\n", $categories_text);
     250        @loclist = sort map { s/^\s+//; s/\s+$//; $_; } # trim lead/trail space
     251                        split("\r\n", $locales_text);
    250252    }
    251253
     
    337339            # integerification by postgres and it's an easy mistake to
    338340            # make when typing into a form.
    339             $os_x =~ s/\s+//;
    340             $os_y =~ s/\s+//;
     341            $os_x =~ s/\s+//g;
     342            $os_y =~ s/\s+//g;
    341343
    342344            # If we were sent x and y, work out lat/long; and vice versa.
     
    380382            my $long   = $q->param("longitude");
    381383
    382             # Trim whitespace - trailing whitespace buggers up the
    383             # integerification by postgres and it's an easy mistake to
    384             # make when typing into a form.
    385             $osie_x =~ s/\s+//;
    386             $osie_y =~ s/\s+//;
     384            # Trim whitespace.
     385            $osie_x =~ s/\s+//g;
     386            $osie_y =~ s/\s+//g;
    387387
    388388            # If we were sent x and y, work out lat/long; and vice versa.
     
    424424            my $long   = $q->param("longitude");
    425425            if ( $lat && $long ) {
     426                # Trim whitespace.
     427                $lat =~ s/\s+//g;
     428                $long =~ s/\s+//g;
    426429                my ($zone, $easting, $northing) =
    427430                 Geo::Coordinates::UTM::latlon_to_utm( $config->ellipsoid,
  • trunk/t/62_bug_trailing_whitespace.t

    r591 r592  
    11use CGI::Wiki::Setup::SQLite;
    22use OpenGuides::Config;
     3use OpenGuides;
    34use OpenGuides::Template;
    45use OpenGuides::Test;
    5 use OpenGuides::Utils;
    6 use Test::More tests => 2;
     6use Test::More;
    77
    88eval { require DBD::SQLite; };
    9 my $have_sqlite = $@ ? 0 : 1;
     9if ( $@ ) {
     10    plan skip_all => "DBD::SQLite not installed";
     11    exit 0;
     12}
     13
     14plan tests => 8;
     15
     16# Clear out the database from any previous runs.
     17unlink "t/node.db";
     18unlink <t/indexes/*>;
     19CGI::Wiki::Setup::SQLite::setup( { dbname => "t/node.db" } );
     20
     21my $config = OpenGuides::Test->make_basic_config;
     22my $guide = OpenGuides->new( config => $config );
    1023
    1124SKIP: {
    12     skip "DBD::SQLite not installed - no database to test with", 2
    13       unless $have_sqlite;
     25    eval { require Geography::NationalGrid::GB; };
     26    skip "Geography::NationalGrid::GB not installed", 2 if $@;
    1427
    15     CGI::Wiki::Setup::SQLite::setup( { dbname => "t/node.db" } );
    16     my $config = OpenGuides::Test->make_basic_config;
    17     my $wiki = OpenGuides::Utils->make_wiki_object( config => $config );
    18 
    19     my $q = CGI->new;
    20     $q->param( -name => "os_x", -value => "123456 " );
    21     $q->param( -name => "os_y", -value => "654321 " );
     28    my $q = CGI->new( "" );
     29    $q->param( -name => "os_x", -value => " 123456 " );
     30    $q->param( -name => "os_y", -value => " 654321 " );
    2231    $q->param( -name => "categories", -value => "" ); #avoid uninit val warning
    2332    $q->param( -name => "locales", -value => "" );    #avoid uninit val warning
    2433
    2534    my %metadata_vars = OpenGuides::Template->extract_metadata_vars(
    26         wiki    => $wiki,
     35        wiki    => $guide->wiki,
    2736        config  => $config,
    2837        cgi_obj => $q,
    2938    );
    3039
    31     is( $metadata_vars{os_x}, "123456", "trailing space stripped from os_x" );
    32     is( $metadata_vars{os_y}, "654321", "trailing space stripped from os_y" );
     40    is( $metadata_vars{os_x}, "123456",
     41        "leading and trailing spaces stripped from os_x when processed" );
     42    is( $metadata_vars{os_y}, "654321", "...and os_y" );
    3343}
     44
     45SKIP: {
     46    eval { require Geography::NationalGrid::IE; };
     47    skip "Geography::NationalGrid::IE not installed", 2 if $@;
     48
     49    $config->geo_handler( 2 );
     50    my $q = CGI->new( "" );
     51    $q->param( -name => "osie_x", -value => " 100000 " );
     52    $q->param( -name => "osie_y", -value => " 200000 " );
     53    $q->param( -name => "categories", -value => "" ); #avoid uninit val warning
     54    $q->param( -name => "locales", -value => "" );    #avoid uninit val warning
     55
     56    my %metadata_vars = OpenGuides::Template->extract_metadata_vars(
     57        wiki    => $guide->wiki,
     58        config  => $config,
     59        cgi_obj => $q,
     60    );
     61
     62    is( $metadata_vars{osie_x}, "100000",
     63        "leading and trailing spaces stripped from osie_x when processed" );
     64    is( $metadata_vars{osie_y}, "200000", "...and osie_y" );
     65}
     66
     67SKIP: {
     68    eval { require Geo::Coordinates::UTM; };
     69    skip "Geo::Coordinates::UTM not installed", 2 if $@;
     70
     71    $config->geo_handler( 3 );
     72    my $q = CGI->new( "" );
     73    $q->param( -name => "latitude", -value => " 1.463113 " );
     74    $q->param( -name => "longitude", -value => " -0.215293 " );
     75    $q->param( -name => "categories", -value => "" ); #avoid uninit val warning
     76    $q->param( -name => "locales", -value => "" );    #avoid uninit val warning
     77
     78    my %metadata_vars = OpenGuides::Template->extract_metadata_vars(
     79        wiki    => $guide->wiki,
     80        config  => $config,
     81        cgi_obj => $q,
     82    );
     83
     84    is( $metadata_vars{latitude}, "1.463113",
     85        "leading and trailing spaces stripped from latitude when processed" );
     86    is( $metadata_vars{longitude}, "-0.215293", "...and longitude" );
     87}
     88
     89OpenGuides::Test->write_data(
     90                              guide => $guide,
     91                              node  => "A Node",
     92                              categories => " Food \r\n Live Music ",
     93                              locales    => " Hammersmith \r\n Fulham ",
     94);
     95my %node = $guide->wiki->retrieve_node( "A Node" );
     96my %data = %{ $node{metadata} };
     97my @cats = sort @{ $data{category} || [] };
     98is_deeply( \@cats, [ "Food", "Live Music" ],
     99    "leading and trailing spaces stripped from all categories when stored" );
     100my @locs = sort @{ $data{locale} || [] };
     101is_deeply( \@locs, [ "Fulham", "Hammersmith" ], "...and all locales" );
Note: See TracChangeset for help on using the changeset viewer.