X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/9fe97ad70f4eba2007801a4c4e083ce86b8d4bbf..d6af4450d1ea3599cdce6921138155f73e154816:/app/controllers/geocoder_controller.rb diff --git a/app/controllers/geocoder_controller.rb b/app/controllers/geocoder_controller.rb index 3431fb8d3..d9b56147f 100644 --- a/app/controllers/geocoder_controller.rb +++ b/app/controllers/geocoder_controller.rb @@ -6,6 +6,7 @@ class GeocoderController < ApplicationController before_action :authorize_web before_action :set_locale before_action :require_oauth, :only => [:search] + authorize_resource :class => false def search @params = normalize_params @@ -16,11 +17,11 @@ class GeocoderController < ApplicationController @sources.push "osm_nominatim_reverse" @sources.push "geonames_reverse" if defined?(GEONAMES_USERNAME) elsif @params[:query] - if @params[:query] =~ /^\d{5}(-\d{4})?$/ + if @params[:query].match?(/^\d{5}(-\d{4})?$/) @sources.push "osm_nominatim" - elsif @params[:query] =~ /^(GIR 0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y]))|[0-9][A-HJKS-UW])\s*[0-9][ABD-HJLNP-UW-Z]{2})$/i + elsif @params[:query].match?(/^(GIR 0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y]))|[0-9][A-HJKS-UW])\s*[0-9][ABD-HJLNP-UW-Z]{2})$/i) @sources.push "osm_nominatim" - elsif @params[:query] =~ /^[A-Z]\d[A-Z]\s*\d[A-Z]\d$/i + elsif @params[:query].match?(/^[A-Z]\d[A-Z]\s*\d[A-Z]\d$/i) @sources.push "ca_postcode" @sources.push "osm_nominatim" else @@ -49,6 +50,7 @@ class GeocoderController < ApplicationController :zoom => params[:zoom], :name => "#{lat}, #{lon}") end + if lon >= -90 && lon <= 90 && lat >= -180 && lat <= 180 @results.push(:lat => lon, :lon => lat, :zoom => params[:zoom], @@ -61,7 +63,6 @@ class GeocoderController < ApplicationController else render :action => "results" end - else # Coordinates in a query have come with markers for latitude and longitude. if lat < -90 || lat > 90 @@ -305,7 +306,9 @@ class GeocoderController < ApplicationController params.merge!(dms_to_decdeg(latlon)).delete(:query) elsif latlon = query.match(/^\s*([+-]?\d+(\.\d*)?)\s*[\s,]\s*([+-]?\d+(\.\d*)?)\s*$/) - params.merge!(:lat => latlon[1].to_f, :lon => latlon[3].to_f, :latlon_digits => true).delete(:query) + params.merge!(:lat => latlon[1].to_f, :lon => latlon[3].to_f).delete(:query) + + params[:latlon_digits] = true unless params[:whereami] end end