Skip to content

Commit

Permalink
Merge pull request #1723 from riganti/static-command-validate-argtype…
Browse files Browse the repository at this point in the history
…-4.2

Validate static command argument type before deserialization (4.2)
  • Loading branch information
tomasherceg authored Oct 22, 2023
2 parents b7d57f0 + 38e1983 commit 9d804f1
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/Framework/Framework/Hosting/StaticCommandExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,26 @@ IDotvvmRequestContext context
IDotvvmRequestContext context
)
{
var parameters = plan.Method.GetParameters();
object? DeserializeArgument(Type type, int index)
{
var parameterType =
plan.Method.IsStatic ? parameters[index].ParameterType :
index == 0 ? plan.Method.DeclaringType :
parameters[index - 1].ParameterType;
if (!parameterType!.IsAssignableFrom(type))
throw new Exception($"Argument {index} has an invalid type");
var arg = arguments.Dequeue();
return arg.ToObject(type, this.jsonDeserializer);
}
var methodArgs = new List<object?>();
var methodArgsPaths = argumentValidationPaths is null ? null : new List<string?>();
foreach (var a in plan.Arguments)
{
var index = methodArgs.Count;
var (value, path) = a.Type switch {
StaticCommandParameterType.Argument =>
((object?)arguments.Dequeue().ToObject((Type)a.Arg!, this.jsonDeserializer), argumentValidationPaths?.Dequeue()),
(DeserializeArgument((Type)a.Arg!, index), argumentValidationPaths?.Dequeue()),
StaticCommandParameterType.Constant or StaticCommandParameterType.DefaultValue =>
(a.Arg, null),
StaticCommandParameterType.Inject =>
Expand Down

0 comments on commit 9d804f1

Please sign in to comment.