Skip to content

Commit 6490d1b

Browse files
committed
call Uri.EscapeDataString on strings used in uris. (#255)
Updated Uri handling per this recommendation to use `Uri.EscapeDataString()`. See also: https://stackoverflow.com/a/34189188/86860
1 parent 4cb73ef commit 6490d1b

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

src/FMData.Rest/FileMakerRestClient.cs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ public override async Task<IResponse> SendAsync(IDeleteRequest req)
617617
#endregion
618618

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

630-
// generate request url{
631-
var uri = $"{FmsUri}/fmi/data/v1/databases/{FileName}/layouts/{layout}/script/{script}";
630+
// generate request url
631+
var uri = $"{FmsUri}/fmi/data/v1"
632+
+ $"/databases/{Uri.EscapeDataString(FileName)}"
633+
+ $"/layouts/{Uri.EscapeDataString(layout)}"
634+
+ $"/script/{Uri.EscapeDataString(script)}";
635+
632636
if (!string.IsNullOrEmpty(scriptParameter))
633637
{
634-
uri += $"?script.param={scriptParameter}";
638+
uri += $"?script.param={Uri.EscapeDataString(scriptParameter)}";
635639
}
636640
var requestMessage = new HttpRequestMessage(HttpMethod.Get, uri);
637641

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

893-
// generate request url{
894-
var uri = $"{FmsUri}/fmi/data/v1/databases/{FileName}/layouts";
897+
// generate request url
898+
var uri = $"{FmsUri}/fmi/data/v1/"
899+
+ $"databases/{Uri.EscapeDataString(FileName)}/layouts";
895900
var requestMessage = new HttpRequestMessage(HttpMethod.Get, uri);
896901

897902
// include auth token
@@ -928,8 +933,9 @@ public override async Task<IReadOnlyCollection<ScriptListItem>> GetScriptsAsync(
928933
{
929934
await UpdateTokenDateAsync().ConfigureAwait(false); // we're about to use the token so update date used
930935

931-
// generate request url{
932-
var uri = $"{FmsUri}/fmi/data/v1/databases/{FileName}/scripts";
936+
// generate request url
937+
var uri = $"{FmsUri}/fmi/data/v1"
938+
+ $"/databases/{Uri.EscapeDataString(FileName)}/scripts";
933939
var requestMessage = new HttpRequestMessage(HttpMethod.Get, uri);
934940

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

971977
// generate request url
972-
var uri = $"{FmsUri}/fmi/data/v1/databases/{FileName}/layouts/{layout}";
978+
var uri = $"{FmsUri}/fmi/data/v1"
979+
+ $"/databases/{Uri.EscapeDataString(FileName)}"
980+
+ $"/layouts/{Uri.EscapeDataString(layout)}";
973981
if (recordId.HasValue)
974982
{
975983
uri += $"?recordId={recordId}";
@@ -1065,7 +1073,7 @@ public override async Task<IEditResponse> UpdateContainerAsync(
10651073
}
10661074

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

0 commit comments

Comments
 (0)