Skip to content
Snippets Groups Projects
Commit 03d929b4 authored by Alex Reisner's avatar Alex Reisner
Browse files

Fix issue #43: don't alter array passed to method.

Reported by github.com/joelmats. The array passed to
Geocoder::Calculations.geographic_center was being modified in-place.
parent d7e40fb1
No related branches found
No related tags found
No related merge requests found
......@@ -120,7 +120,7 @@ module Geocoder
def geographic_center(points)
# convert objects to [lat,lon] arrays and remove nils
points.map!{ |p| p.is_a?(Array) ? p : p.to_coordinates }.compact
points = points.map{ |p| p.is_a?(Array) ? p : p.to_coordinates }.compact
# convert degrees to radians
points.map!{ |p| to_radians(p) }
......
......@@ -51,6 +51,14 @@ class GeocoderTest < Test::Unit::TestCase
assert Geocoder.address(40.750354, -73.993371).is_a?(String)
end
def test_geographic_center_doesnt_overwrite_argument_value
# this tests for the presence of a bug that was introduced in version 0.9.11
orig_points = [[52,8], [46,9], [42,5]]
points = orig_points.clone
Geocoder::Calculations.geographic_center(points)
assert_equal orig_points, points
end
# --- general ---
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment