Author: kake Date: 2012-05-02 14:39:43 +0100 (Wed, 02 May 2012) New Revision: 1374
Modified: trunk/lib/OpenGuides/Template.pm trunk/t/68_bug_website_displayed.t Log: And strip trailing / from displayed websites when it's the only / in the URL.
Modified: trunk/lib/OpenGuides/Template.pm =================================================================== --- trunk/lib/OpenGuides/Template.pm 2012-05-02 13:14:07 UTC (rev 1373) +++ trunk/lib/OpenGuides/Template.pm 2012-05-02 13:39:43 UTC (rev 1374) @@ -366,11 +366,17 @@
my $website = $args{metadata} ? $metadata{website}[0] : $q->param("website"); + # Do truncation for website name display. Max length of field is set in + # conf file (website_link_max_chars). Leading http:// and www. if present + # is stripped; trailing / is also stripped if it's the only / in the URL. my $formatted_website_text = ""; if ( $website && $website ne "http://" && is_web_uri( $website ) ) { my $maxlen = $config->website_link_max_chars; my $trunc_website = $website; $trunc_website =~ s|http://(www.)?%7C%7C; + if ( $trunc_website =~ tr|/|| == 1 ) { + $trunc_website =~ s|/$||; + } if ( length( $trunc_website ) > $maxlen ) { $trunc_website = substr( $trunc_website, 0, $maxlen - 3 ) . "..."; }
Modified: trunk/t/68_bug_website_displayed.t =================================================================== --- trunk/t/68_bug_website_displayed.t 2012-05-02 13:14:07 UTC (rev 1373) +++ trunk/t/68_bug_website_displayed.t 2012-05-02 13:39:43 UTC (rev 1374) @@ -11,7 +11,7 @@ plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)"; }
-plan tests => 6; +plan tests => 7;
OpenGuides::Test::refresh_db();
@@ -24,12 +24,16 @@ "A busy main-line station that actually exists.", undef, { website => "http://www.example.com/foo" } ) or die "Couldn't write node"; +$guide->wiki->write_node( "West Croydon Station", + "Another main-line station that actually exists.", undef, + { website => "http://www.example.com/bar/" } ) + or die "Couldn't write node";
$config->website_link_max_chars( 20 ); my %tt_vars = $guide->display_node( id => "South Croydon Station", return_tt_vars => 1 ); is( $tt_vars{formatted_website_text}, - '<a href="http://example.com/">example.com/</a>', + '<a href="http://example.com/">example.com</a>', "Website correctly displayed when no need for truncation," );
%tt_vars = $guide->display_node( id => "East Croydon Station", @@ -38,6 +42,12 @@ '<a href="http://www.example.com/foo">example.com/foo</a>', "Website correctly truncated when there's a leading www" );
+%tt_vars = $guide->display_node( id => "West Croydon Station", + return_tt_vars => 1 ); +is( $tt_vars{formatted_website_text}, + '<a href="http://www.example.com/bar/">example.com/bar/</a>', + "Trailing slash not stripped unless it's immediately after domain name" ); + %tt_vars = $guide->display_node( id => "North Croydon Station", return_tt_vars => 1 ); is( $tt_vars{formatted_website_text},
openguides-commits@lists.openguides.org