From d3d0ab6d5a753d1e5c8277db981f03823683ae1f Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Tue, 15 Mar 2016 16:41:44 +0000 Subject: Don't double-decode geocoded addresses. Perl 5.20 introduced a version of Encode that errors on decoding already decoded content (rather than returning the same string). Whilst this can be taken as a bug in our code (although the decoding exists because some versions of FastCGI silently UTF-8 encode the content), in the changelog for Perl the only reference to this change is the line: "Encode has been upgraded from version 2.49 to 2.60.". --- perllib/FixMyStreet/App/Controller/Around.pm | 6 ++++-- perllib/FixMyStreet/App/Controller/Location.pm | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm index 5ccab4047..1e6d9ec9e 100644 --- a/perllib/FixMyStreet/App/Controller/Around.pm +++ b/perllib/FixMyStreet/App/Controller/Around.pm @@ -351,8 +351,10 @@ sub _geocode : Private { } else { if ( ref($suggestions) eq 'ARRAY' ) { foreach (@$suggestions) { - push @addresses, decode_utf8($_->{address}); - push @locations, { address => decode_utf8($_->{address}), lat => $_->{latitude}, long => $_->{longitude} }; + my $address = $_->{address}; + $address = decode_utf8($address) if !utf8::is_utf8($address); + push @addresses, $address; + push @locations, { address => $address, lat => $_->{latitude}, long => $_->{longitude} }; } $response = { suggestions => \@addresses, locations => \@locations }; } else { diff --git a/perllib/FixMyStreet/App/Controller/Location.pm b/perllib/FixMyStreet/App/Controller/Location.pm index ff90d3d60..6def423ce 100644 --- a/perllib/FixMyStreet/App/Controller/Location.pm +++ b/perllib/FixMyStreet/App/Controller/Location.pm @@ -95,7 +95,8 @@ sub determine_location_from_pc : Private { # $error doubles up to return multiple choices by being an array if ( ref($error) eq 'ARRAY' ) { foreach (@$error) { - my $a = decode_utf8($_->{address}); + my $a = $_->{address}; + $a = decode_utf8($a) if !utf8::is_utf8($a); $a =~ s/, United Kingdom//; $a =~ s/, UK//; $_->{address} = $a; -- cgit v1.2.3