Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mapbox-geocoding): fixing an issue where the query is not properly encoded, and fixing an issue where the query string building is using an outdated method #46

Merged
merged 4 commits into from
Aug 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 52 additions & 51 deletions src/Geo.ArcGIS/Services/ArcGISGeocoding.cs

Large diffs are not rendered by default.

49 changes: 24 additions & 25 deletions src/Geo.Bing/Services/BingGeocoding.cs
Original file line number Diff line number Diff line change
@@ -6,18 +6,17 @@
namespace Geo.Bing.Services
{
using System;
using System.Collections.Specialized;
using System.Configuration;
using System.Globalization;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using Geo.Bing.Abstractions;
using Geo.Bing.Models.Exceptions;
using Geo.Bing.Models.Parameters;
using Geo.Bing.Models.Responses;
using Geo.Core;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
@@ -120,7 +119,7 @@ internal Uri ValidateAndBuildUri<TParameters>(TParameters parameters, Func<TPara
internal Uri BuildGeocodingRequest(GeocodingParameters parameters)
{
var uriBuilder = new UriBuilder(BaseUri);
var query = HttpUtility.ParseQueryString(uriBuilder.Query);
var query = QueryString.Empty;

if (string.IsNullOrWhiteSpace(parameters.Query))
{
@@ -129,11 +128,11 @@ internal Uri BuildGeocodingRequest(GeocodingParameters parameters)
throw new ArgumentException(error, nameof(parameters.Query));
}

query.Add("query", parameters.Query);
query = query.Add("query", parameters.Query);

BuildLimitedResultQuery(parameters, ref query);

AddBingKey(query);
AddBingKey(ref query);

uriBuilder.Query = query.ToString();

@@ -156,7 +155,7 @@ internal Uri BuildReverseGeocodingRequest(ReverseGeocodingParameters parameters)
}

var uriBuilder = new UriBuilder(BaseUri + $"/{parameters.Point}");
var query = HttpUtility.ParseQueryString(uriBuilder.Query);
var query = QueryString.Empty;

var includes = new CommaDelimitedStringCollection();
if (parameters.IncludeAddress == true)
@@ -196,7 +195,7 @@ internal Uri BuildReverseGeocodingRequest(ReverseGeocodingParameters parameters)

if (includes.Count > 0)
{
query.Add("includeEntityTypes", includes.ToString());
query = query.Add("includeEntityTypes", includes.ToString());
}
else
{
@@ -205,7 +204,7 @@ internal Uri BuildReverseGeocodingRequest(ReverseGeocodingParameters parameters)

BuildBaseQuery(parameters, ref query);

AddBingKey(query);
AddBingKey(ref query);

uriBuilder.Query = query.ToString();

@@ -232,11 +231,11 @@ internal Uri BuildAddressGeocodingRequest(AddressGeocodingParameters parameters)
}

var uriBuilder = new UriBuilder(BaseUri);
var query = HttpUtility.ParseQueryString(uriBuilder.Query);
var query = QueryString.Empty;

if (!string.IsNullOrWhiteSpace(parameters.AdministrationDistrict))
{
query.Add("adminDistrict", parameters.AdministrationDistrict);
query = query.Add("adminDistrict", parameters.AdministrationDistrict);
}
else
{
@@ -245,7 +244,7 @@ internal Uri BuildAddressGeocodingRequest(AddressGeocodingParameters parameters)

if (!string.IsNullOrWhiteSpace(parameters.Locality))
{
query.Add("locality", parameters.Locality);
query = query.Add("locality", parameters.Locality);
}
else
{
@@ -254,7 +253,7 @@ internal Uri BuildAddressGeocodingRequest(AddressGeocodingParameters parameters)

if (!string.IsNullOrWhiteSpace(parameters.PostalCode))
{
query.Add("postalCode", parameters.PostalCode);
query = query.Add("postalCode", parameters.PostalCode);
}
else
{
@@ -263,7 +262,7 @@ internal Uri BuildAddressGeocodingRequest(AddressGeocodingParameters parameters)

if (!string.IsNullOrWhiteSpace(parameters.AddressLine))
{
query.Add("addressLine", parameters.AddressLine);
query = query.Add("addressLine", parameters.AddressLine);
}
else
{
@@ -272,7 +271,7 @@ internal Uri BuildAddressGeocodingRequest(AddressGeocodingParameters parameters)

if (parameters.CountryRegion != null)
{
query.Add("countryRegion", parameters.CountryRegion.TwoLetterISORegionName.ToUpperInvariant());
query = query.Add("countryRegion", parameters.CountryRegion.TwoLetterISORegionName.ToUpperInvariant());
}
else
{
@@ -281,7 +280,7 @@ internal Uri BuildAddressGeocodingRequest(AddressGeocodingParameters parameters)

BuildLimitedResultQuery(parameters, ref query);

AddBingKey(query);
AddBingKey(ref query);

uriBuilder.Query = query.ToString();

@@ -292,12 +291,12 @@ internal Uri BuildAddressGeocodingRequest(AddressGeocodingParameters parameters)
/// Builds up the limited result query parameters.
/// </summary>
/// <param name="parameters">A <see cref="ResultParameters"/> with the limited result parameters to build the uri with.</param>
/// <param name="query">A <see cref="NameValueCollection"/> with the built up query parameters.</param>
internal void BuildLimitedResultQuery(ResultParameters parameters, ref NameValueCollection query)
/// <param name="query">A <see cref="QueryString"/> with the built up query parameters.</param>
internal void BuildLimitedResultQuery(ResultParameters parameters, ref QueryString query)
{
if (parameters.MaximumResults > 0 && parameters.MaximumResults <= 20)
{
query.Add("maxResults", parameters.MaximumResults.ToString(CultureInfo.InvariantCulture));
query = query.Add("maxResults", parameters.MaximumResults.ToString(CultureInfo.InvariantCulture));
}
else
{
@@ -311,12 +310,12 @@ internal void BuildLimitedResultQuery(ResultParameters parameters, ref NameValue
/// Builds up the base query parameters.
/// </summary>
/// <param name="parameters">A <see cref="BaseParameters"/> with the base parameters to build the uri with.</param>
/// <param name="query">A <see cref="NameValueCollection"/> with the built up query parameters.</param>
internal void BuildBaseQuery(BaseParameters parameters, ref NameValueCollection query)
/// <param name="query">A <see cref="QueryString"/> with the built up query parameters.</param>
internal void BuildBaseQuery(BaseParameters parameters, ref QueryString query)
{
if (parameters.IncludeNeighbourhood == true)
{
query.Add("includeNeighborhood", "1");
query = query.Add("includeNeighborhood", "1");
}
else
{
@@ -336,7 +335,7 @@ internal void BuildBaseQuery(BaseParameters parameters, ref NameValueCollection

if (includes.Count > 0)
{
query.Add("include", includes.ToString());
query = query.Add("include", includes.ToString());
}
else
{
@@ -347,10 +346,10 @@ internal void BuildBaseQuery(BaseParameters parameters, ref NameValueCollection
/// <summary>
/// Adds the Bing key to the query parameters.
/// </summary>
/// <param name="query">A <see cref="NameValueCollection"/> with the query parameters.</param>
internal void AddBingKey(NameValueCollection query)
/// <param name="query">A <see cref="QueryString"/> with the query parameters.</param>
internal void AddBingKey(ref QueryString query)
{
query.Add("key", _keyContainer.GetKey());
query = query.Add("key", _keyContainer.GetKey());
}
}
}
Loading