diff options
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Reports.pm | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index 8cebc0e60..98a3c8927 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -90,6 +90,7 @@ sub ward : Path : Args(2) { $c->forward( 'ward_check', [ $ward ] ) if $ward; $c->forward( 'load_parent' ); + $c->forward( 'check_canonical_url', [ $council ] ); $c->forward( 'load_and_group_problems' ); $c->forward( 'sort_problems' ); @@ -226,7 +227,7 @@ sub council_check : Private { return; } else { foreach (keys %$areas) { - if ($areas->{$_}->{name} eq $q_council || $areas->{$_}->{name} =~ /^\Q$q_council\E (Borough|City|District|County) Council$/) { + if (lc($areas->{$_}->{name}) eq lc($q_council) || $areas->{$_}->{name} =~ /^\Q$q_council\E (Borough|City|District|County) Council$/i) { $c->stash->{council} = $areas->{$_}; return; } @@ -281,6 +282,22 @@ sub load_parent : Private { } } +=head2 check_canonical_url + +Given an already found (case-insensitively) council, check what URL +we are at and redirect accordingly if different. + +=cut + +sub check_canonical_url : Private { + my ( $self, $c, $q_council ) = @_; + + my $council_short = $c->cobrand->short_name( $c->stash->{council}, $c->stash->{areas_info} ); + my $url_short = URI::Escape::uri_escape_utf8($q_council); + $url_short =~ s/%2B/+/g; + $c->detach( 'redirect_area' ) unless $council_short eq $url_short; +} + sub load_and_group_problems : Private { my ( $self, $c ) = @_; @@ -369,7 +386,7 @@ sub redirect_area : Private { my $url = ''; $url .= "/rss" if $c->stash->{rss}; $url .= '/reports'; - $url .= '/' . $c->cobrand->short_name( $c->stash->{council} ); + $url .= '/' . $c->cobrand->short_name( $c->stash->{council}, $c->stash->{areas_info} ); $url .= '/' . $c->cobrand->short_name( $c->stash->{ward} ) if $c->stash->{ward}; $c->res->redirect( $c->uri_for($url) ); |