Skip to content

Commit

Permalink
call Uri.EscapeDataString on strings used in uris. (#255)
Browse files Browse the repository at this point in the history
Updated Uri handling per this recommendation to use
`Uri.EscapeDataString()`.

See also: https://stackoverflow.com/a/34189188/86860
  • Loading branch information
fuzzzerd authored Oct 12, 2022
1 parent a6fbff6 commit 4cf2ece
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/FMData.Rest/FileMakerRestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ public override async Task<IResponse> SendAsync(IDeleteRequest req)
#endregion

/// <summary>
/// Runs a script with the specified layout context and with an optional (null/empty OK) paramater.
/// Runs a script with the specified layout context and with an optional (null/empty OK) parameter.
/// </summary>
/// <param name="layout">The layout to use for the context of the script.</param>
/// <param name="script">The name of the script to run.</param>
Expand All @@ -634,11 +634,15 @@ public override async Task<string> RunScriptAsync(string layout, string script,
{
await UpdateTokenDateAsync().ConfigureAwait(false); // we're about to use the token so update date used

// generate request url{
var uri = $"{FmsUri}/fmi/data/v1/databases/{FileName}/layouts/{layout}/script/{script}";
// generate request url
var uri = $"{FmsUri}/fmi/data/v1"
+ $"/databases/{Uri.EscapeDataString(FileName)}"
+ $"/layouts/{Uri.EscapeDataString(layout)}"
+ $"/script/{Uri.EscapeDataString(script)}";

if (!string.IsNullOrEmpty(scriptParameter))
{
uri += $"?script.param={scriptParameter}";
uri += $"?script.param={Uri.EscapeDataString(scriptParameter)}";
}
var requestMessage = new HttpRequestMessage(HttpMethod.Get, uri);

Expand Down Expand Up @@ -894,8 +898,9 @@ public override async Task<IReadOnlyCollection<LayoutListItem>> GetLayoutsAsync(
{
await UpdateTokenDateAsync().ConfigureAwait(false); // we're about to use the token so update date used

// generate request url{
var uri = $"{FmsUri}/fmi/data/v1/databases/{FileName}/layouts";
// generate request url
var uri = $"{FmsUri}/fmi/data/v1/"
+ $"databases/{Uri.EscapeDataString(FileName)}/layouts";
var requestMessage = new HttpRequestMessage(HttpMethod.Get, uri);

// include auth token
Expand Down Expand Up @@ -932,8 +937,9 @@ public override async Task<IReadOnlyCollection<ScriptListItem>> GetScriptsAsync(
{
await UpdateTokenDateAsync().ConfigureAwait(false); // we're about to use the token so update date used

// generate request url{
var uri = $"{FmsUri}/fmi/data/v1/databases/{FileName}/scripts";
// generate request url
var uri = $"{FmsUri}/fmi/data/v1"
+ $"/databases/{Uri.EscapeDataString(FileName)}/scripts";
var requestMessage = new HttpRequestMessage(HttpMethod.Get, uri);

// include auth token
Expand Down Expand Up @@ -973,7 +979,9 @@ public override async Task<LayoutMetadata> GetLayoutAsync(string layout, int? re
await UpdateTokenDateAsync().ConfigureAwait(false); // we're about to use the token so update date used

// generate request url
var uri = $"{FmsUri}/fmi/data/v1/databases/{FileName}/layouts/{layout}";
var uri = $"{FmsUri}/fmi/data/v1"
+ $"/databases/{Uri.EscapeDataString(FileName)}"
+ $"/layouts/{Uri.EscapeDataString(layout)}";
if (recordId.HasValue)
{
uri += $"?recordId={recordId}";
Expand Down Expand Up @@ -1069,7 +1077,7 @@ public override async Task<IEditResponse> UpdateContainerAsync(
}

/// <summary>
/// Utility method that must be overridden in implementations. Takes a containerfield url and populates a byte array utilizing the instance's http client.
/// Utility method that must be overridden in implementations. Takes a container field url and populates a byte array utilizing the instance's http client.
/// </summary>
/// <param name="containerEndPoint">The container field to load.</param>
/// <returns>An array of bytes with the data from the container field.</returns>
Expand Down

0 comments on commit 4cf2ece

Please sign in to comment.