Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using Alba;
using IntegrationTests;
using Marten;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Wolverine.Marten;

namespace Wolverine.Http.Tests.Bugs;

public class Bug_1961_reserved_characters_in_form_field
{
[Fact]
public async Task generate_code_correctly()
{

var builder = WebApplication.CreateBuilder([]);

builder.Services.AddMarten(opts =>
{
// Establish the connection string to your Marten database
opts.Connection(Servers.PostgresConnectionString);
opts.DisableNpgsqlLogging = true;
}).IntegrateWithWolverine();

builder.Host.UseWolverine(opts =>
{
opts.Discovery.DisableConventionalDiscovery().IncludeType(typeof(TrainingRequestHandler));
opts.ApplicationAssembly = GetType().Assembly;
});

builder.Services.AddWolverineHttp();

// This is using Alba, which uses WebApplicationFactory under the covers
await using var host = await AlbaHost.For(builder, app =>
{
app.MapWolverineEndpoints(x =>
{

});
});

var result = await host.Scenario(x =>
{
x.Post.FormData(new (){ { "rechtliche_hinweise/akzeptiert", "Albert" } })
.ToUrl("/angebot/training");

x.StatusCodeShouldBe(302);
});
}
}

// For https://github.com/JasperFx/wolverine/issues/1961
public record TrainingRequest(
[FromForm(Name = "rechtliche_hinweise/akzeptiert")]
bool? rechtlicheHinweiseAkzeptiert
);

public static class TrainingRequestHandler
{
[WolverinePost("angebot/training")]
public static IResult Post([AsParameters()]TrainingRequest egal)

{
return Results.Redirect($"/vielen-dank");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ namespace Internal.Generated.WolverineHandlers
public sealed class GET_todo_id : Wolverine.Http.HttpHandler
{
private readonly Wolverine.Http.WolverineHttpOptions _wolverineHttpOptions;
private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory;
private readonly Wolverine.Runtime.IWolverineRuntime _wolverineRuntime;
private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory;

public GET_todo_id(Wolverine.Http.WolverineHttpOptions wolverineHttpOptions, Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory, Wolverine.Runtime.IWolverineRuntime wolverineRuntime) : base(wolverineHttpOptions)
public GET_todo_id(Wolverine.Http.WolverineHttpOptions wolverineHttpOptions, Wolverine.Runtime.IWolverineRuntime wolverineRuntime, Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory) : base(wolverineHttpOptions)
{
_wolverineHttpOptions = wolverineHttpOptions;
_outboxedSessionFactory = outboxedSessionFactory;
_wolverineRuntime = wolverineRuntime;
_outboxedSessionFactory = outboxedSessionFactory;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ namespace Internal.Generated.WolverineHandlers
public sealed class POST_todo_create : Wolverine.Http.HttpHandler
{
private readonly Wolverine.Http.WolverineHttpOptions _wolverineHttpOptions;
private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory;
private readonly Wolverine.Runtime.IWolverineRuntime _wolverineRuntime;
private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory;

public POST_todo_create(Wolverine.Http.WolverineHttpOptions wolverineHttpOptions, Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory, Wolverine.Runtime.IWolverineRuntime wolverineRuntime) : base(wolverineHttpOptions)
public POST_todo_create(Wolverine.Http.WolverineHttpOptions wolverineHttpOptions, Wolverine.Runtime.IWolverineRuntime wolverineRuntime, Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory) : base(wolverineHttpOptions)
{
_wolverineHttpOptions = wolverineHttpOptions;
_outboxedSessionFactory = outboxedSessionFactory;
_wolverineRuntime = wolverineRuntime;
_outboxedSessionFactory = outboxedSessionFactory;
}


Expand Down
1 change: 1 addition & 0 deletions src/Http/Wolverine.Http.Tests/asparameters_binding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using WolverineWebApi;
using WolverineWebApi.Forms;

namespace Wolverine.Http.Tests;

Expand Down
1 change: 1 addition & 0 deletions src/Http/Wolverine.Http.Tests/using_form_parameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Wolverine.Http.CodeGen;
using Wolverine.Runtime;
using WolverineWebApi;
using WolverineWebApi.Forms;

namespace Wolverine.Http.Tests;

Expand Down
9 changes: 9 additions & 0 deletions src/Http/Wolverine.Http/CodeGen/CodeGenExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Wolverine.Http.CodeGen;

internal static class CodeGenExtensions
{
public static string SanitizeFormNameForVariable(this string variableName)
{
return variableName.Replace("/", "_");
}
}
2 changes: 1 addition & 1 deletion src/Http/Wolverine.Http/CodeGen/HttpElementVariable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class HttpElementVariable : Variable
{
public HttpElementVariable(Type variableType, string usage, Frame? creator) : base(variableType, usage, creator)
{
Name = usage;
Name = usage.SanitizeFormNameForVariable();
}

public string Name { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Wolverine.Http/CodeGen/IReadHttpFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal class ReadHttpFrame : SyncFrame, IReadHttpFrame
public ReadHttpFrame(BindingSource source, Type parameterType, string parameterName, bool isOptional = false)
{
_source = source;
Variable = new HttpElementVariable(parameterType, parameterName!, this);
Variable = new HttpElementVariable(parameterType, parameterName!.SanitizeFormNameForVariable(), this);

_isOptional = isOptional;
_isNullable = parameterType.IsNullable();
Expand Down
2 changes: 0 additions & 2 deletions src/Http/Wolverine.Http/HttpChain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -409,13 +409,11 @@ private void applyMetadata()
if (parameterType == typeof(string))
{
variable = new ReadHttpFrame(BindingSource.Form, parameterType,key).Variable;
variable.Name = key;
_formValueVariables.Add(variable);
}
if (parameterType == typeof(string[]))
{
variable = new ParsedArrayFormValue(parameterType, parameterName).Variable;
variable.Name = key;
_formValueVariables.Add(variable);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
using Marten;
using Microsoft.AspNetCore.Mvc;
using Shouldly;
using Spectre.Console;
using Wolverine.Http;

namespace WolverineWebApi;
namespace WolverineWebApi.Forms;

//Uses same test data as QuerystringEndpoints
public static class FormEndpoints{
Expand Down
Loading