Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane32 committed Jan 22, 2024
1 parent bb7d5f2 commit db763a7
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 68 deletions.
38 changes: 16 additions & 22 deletions src/Transports.AspNetCore/GraphQLHttpMiddleware.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma warning disable CA1716 // Identifiers should not match keywords

using System.Collections;
using System.Diagnostics;
using System.Globalization;
using System.Text;
using Microsoft.AspNetCore.Authentication;
Expand Down Expand Up @@ -326,29 +327,22 @@ void ApplyMapToRequests(Dictionary<string, string?[]> map, IFormCollection form,
throw new FileSizeExceededError();
}

try
foreach (var entry in map)
{
foreach (var entry in map)
// validate entry key
if (entry.Key == "" || entry.Key == "query" || entry.Key == "operationName" || entry.Key == "variables" || entry.Key == "extensions" || entry.Key == "operations" || entry.Key == "map")
throw new InvalidMapError("Map key cannot be query, operationName, variables, extensions, operations or map.");
// locate file
var file = form.Files[entry.Key]
?? throw new InvalidMapError("Map key does not refer to an uploaded file.");
// apply file to each target
foreach (var target in entry.Value)
{
// validate entry key
if (entry.Key == "" || entry.Key == "query" || entry.Key == "operationName" || entry.Key == "variables" || entry.Key == "extensions" || entry.Key == "operations" || entry.Key == "map")
throw new InvalidMapError("Map key cannot be query, operationName, variables, extensions, operations or map.");
// locate file
var file = form.Files[entry.Key]
?? throw new InvalidMapError("Map key does not refer to an uploaded file.");
// apply file to each target
foreach (var target in entry.Value)
{
if (target != null)
ApplyFileToRequests(file, target, requests);
}
if (target == null)
throw new InvalidMapError("Map target cannot be null.");
ApplyFileToRequests(file, target, requests);
}
}
// catch unanticipated exceptions, although this should never happen
catch (Exception ex) when (ex is not ExecutionError)
{
throw new InvalidMapError(ex);
}
}

// Applies an uploaded file to a specific target property within a list of requests.
Expand Down Expand Up @@ -436,9 +430,9 @@ static void ApplyFileToRequest(IFormFile file, string target, GraphQLRequest? re
prop = location;
}

// Verify that the target is valid
if (prop == null || prop.Length == 0)
throw new InvalidMapError("No map path provided.");
// Verify that the target is valid (should not be possible)
Debug.Assert(prop != null);
Debug.Assert(prop!.Length > 0);

// Resolve the segment, and set it to the form file

Expand Down
Loading

0 comments on commit db763a7

Please sign in to comment.