aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/App/Controller/Around.pm6
-rw-r--r--perllib/FixMyStreet/App/Controller/Location.pm1
-rw-r--r--perllib/FixMyStreet/Geocode.pm9
-rw-r--r--t/Mock/Nominatim.pm5
-rw-r--r--t/cobrand/fixamingata.t10
5 files changed, 17 insertions, 14 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm
index b872084ff..44ccb5259 100644
--- a/perllib/FixMyStreet/App/Controller/Around.pm
+++ b/perllib/FixMyStreet/App/Controller/Around.pm
@@ -338,10 +338,8 @@ sub _geocode : Private {
} else {
if ( ref($suggestions) eq 'ARRAY' ) {
foreach (@$suggestions) {
- my $address = $_->{address};
- $address = decode_utf8($address) if !utf8::is_utf8($address);
- push @addresses, $address;
- push @locations, { address => $address, lat => $_->{latitude}, long => $_->{longitude} };
+ 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 c457c8fce..cb2077ede 100644
--- a/perllib/FixMyStreet/App/Controller/Location.pm
+++ b/perllib/FixMyStreet/App/Controller/Location.pm
@@ -96,7 +96,6 @@ sub determine_location_from_pc : Private {
if ( ref($error) eq 'ARRAY' ) {
foreach (@$error) {
my $a = $_->{address};
- $a = decode_utf8($a) if !utf8::is_utf8($a);
$a =~ s/, United Kingdom//;
$a =~ s/, UK//;
$_->{address} = $a;
diff --git a/perllib/FixMyStreet/Geocode.pm b/perllib/FixMyStreet/Geocode.pm
index b5bb7249c..dd1adfe71 100644
--- a/perllib/FixMyStreet/Geocode.pm
+++ b/perllib/FixMyStreet/Geocode.pm
@@ -73,18 +73,19 @@ sub cache {
my $cache_file = $cache_dir->child(md5_hex($url));
my $js;
if (-s $cache_file && -M $cache_file <= 7 && !FixMyStreet->config('STAGING_SITE')) {
- $js = $cache_file->slurp;
+ # uncoverable statement
+ $js = $cache_file->slurp_utf8;
} else {
$url .= '&' . $args if $args;
$ua->timeout(15);
$js = LWP::Simple::get($url);
- $js = encode_utf8($js) if utf8::is_utf8($js);
$cache_dir->mkpath;
if ($js && (!$re || $js !~ $re) && !FixMyStreet->config('STAGING_SITE')) {
- $cache_file->spew($js);
+ # uncoverable statement
+ $cache_file->spew_utf8($js);
}
}
- $js = JSON->new->utf8->allow_nonref->decode($js) if $js;
+ $js = JSON->new->allow_nonref->decode($js) if $js;
return $js;
}
diff --git a/t/Mock/Nominatim.pm b/t/Mock/Nominatim.pm
index 5c8c549d1..5edbc9b30 100644
--- a/t/Mock/Nominatim.pm
+++ b/t/Mock/Nominatim.pm
@@ -13,6 +13,11 @@ has json => (
sub dispatch_request {
my $self = shift;
+ sub (GET + /reverse + ?*) {
+ my ($self) = @_;
+ return [ 200, [ 'Content-Type' => 'text/xml' ], [ '<result></result>' ] ];
+ },
+
sub (GET + /search + ?q=) {
my ($self, $q) = @_;
my $response = $self->query($q);
diff --git a/t/cobrand/fixamingata.t b/t/cobrand/fixamingata.t
index 1e6bd7e65..06b5830e3 100644
--- a/t/cobrand/fixamingata.t
+++ b/t/cobrand/fixamingata.t
@@ -1,13 +1,10 @@
-use Test::MockModule;
-
use mySociety::Locale;
use FixMyStreet::TestMech;
my $mech = FixMyStreet::TestMech->new;
-# Closest road reverse geocode mock
-my $resolver = Test::MockModule->new('LWP::Simple');
-$resolver->mock('get', sub($) { "<result></result>" });
+use t::Mock::Nominatim;
+LWP::Protocol::PSGI->register(t::Mock::Nominatim->to_psgi_app, host => 'nominatim.openstreetmap.org');
# Front page test
@@ -103,6 +100,9 @@ subtest "Test ajax decimal points" => sub {
$mech->get_ok('/ajax/lookup_location?term=12345');
# We want an actual decimal point in a JSON response...
$mech->content_contains('51.5');
+
+ $mech->get_ok('/ajax/lookup_location?term=high+street');
+ $mech->content_contains('Edinburgh');
};
};