format and encode query before sending
This commit is contained in:
parent
e607502d13
commit
8b8248388f
@ -12,6 +12,7 @@ using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using System.Net;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Salesforce.NET
|
||||
{
|
||||
@ -408,6 +409,9 @@ namespace Salesforce.NET
|
||||
/// <returns></returns>
|
||||
public async Task<ICollection<T>> QueryAsync<T>(string query)
|
||||
{
|
||||
// clean up query and encode prior to sending
|
||||
query = FormatQuery(query);
|
||||
|
||||
var queryApiUrl = await GetEndpointUrlAsync($"query?q={query}");
|
||||
|
||||
return await InvokeRequestAsync(async httpClient =>
|
||||
@ -649,6 +653,15 @@ namespace Salesforce.NET
|
||||
}
|
||||
}
|
||||
|
||||
private static string FormatQuery(string query)
|
||||
{
|
||||
query = Regex.Replace(query, "[\r\n\t]", string.Empty);
|
||||
query = Regex.Replace(query, "[ ]{2,}", " ");
|
||||
query = WebUtility.UrlEncode(query);
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user