diff options
author | Matthew Somerville <matthew@mysociety.org> | 2016-03-15 16:41:44 +0000 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2016-03-15 17:28:44 +0000 |
commit | d3d0ab6d5a753d1e5c8277db981f03823683ae1f (patch) | |
tree | f3fbdd406aedc27715e466c2c78fae747d600694 | |
parent | 4eef3c7e5d067fcf76da2970c957bd34d257a013 (diff) |
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.".
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Around.pm | 6 | ||||
-rw-r--r-- | 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; |