Skip to content

Commit 4cf2ece

Browse files
authored
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 a6fbff6 commit 4cf2ece

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/FMData.Rest/FileMakerRestClient.cs

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

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

637-
// generate request url{
638-
var uri = $"{FmsUri}/fmi/data/v1/databases/{FileName}/layouts/{layout}/script/{script}";
637+
// generate request url
638+
var uri = $"{FmsUri}/fmi/data/v1"
639+
+ $"/databases/{Uri.EscapeDataString(FileName)}"
640+
+ $"/layouts/{Uri.EscapeDataString(layout)}"
641+
+ $"/script/{Uri.EscapeDataString(script)}";
642+
639643
if (!string.IsNullOrEmpty(scriptParameter))
640644
{
641-
uri += $"?script.param={scriptParameter}";
645+
uri += $"?script.param={Uri.EscapeDataString(scriptParameter)}";
642646
}
643647
var requestMessage = new HttpRequestMessage(HttpMethod.Get, uri);
644648

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

897-
// generate request url{
898-
var uri = $"{FmsUri}/fmi/data/v1/databases/{FileName}/layouts";
901+
// generate request url
902+
var uri = $"{FmsUri}/fmi/data/v1/"
903+
+ $"databases/{Uri.EscapeDataString(FileName)}/layouts";
899904
var requestMessage = new HttpRequestMessage(HttpMethod.Get, uri);
900905

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

935-
// generate request url{
936-
var uri = $"{FmsUri}/fmi/data/v1/databases/{FileName}/scripts";
940+
// generate request url
941+
var uri = $"{FmsUri}/fmi/data/v1"
942+
+ $"/databases/{Uri.EscapeDataString(FileName)}/scripts";
937943
var requestMessage = new HttpRequestMessage(HttpMethod.Get, uri);
938944

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

975981
// generate request url
976-
var uri = $"{FmsUri}/fmi/data/v1/databases/{FileName}/layouts/{layout}";
982+
var uri = $"{FmsUri}/fmi/data/v1"
983+
+ $"/databases/{Uri.EscapeDataString(FileName)}"
984+
+ $"/layouts/{Uri.EscapeDataString(layout)}";
977985
if (recordId.HasValue)
978986
{
979987
uri += $"?recordId={recordId}";
@@ -1069,7 +1077,7 @@ public override async Task<IEditResponse> UpdateContainerAsync(
10691077
}
10701078

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

0 commit comments

Comments
 (0)