Skip to content

Commit 28e7b26

Browse files
javiercngithub-actions
authored andcommitted
Address feedback
1 parent 83880f7 commit 28e7b26

File tree

8 files changed

+19
-39
lines changed

8 files changed

+19
-39
lines changed

src/Components/Endpoints/src/Binding/DefaultFormValuesSupplier.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void Bind(FormValueSupplierContext context)
5050

5151
var deserializer = _cache.GetOrAdd(context.ValueType, CreateDeserializer);
5252
Debug.Assert(deserializer != null);
53-
deserializer.Deserialize(context, _options, _formData.Entries, _formData.FormOptions);
53+
deserializer.Deserialize(context, _options, _formData.Entries);
5454
}
5555

5656
private FormValueSupplier CreateDeserializer(Type type) =>
@@ -62,17 +62,15 @@ internal abstract class FormValueSupplier
6262
public abstract void Deserialize(
6363
FormValueSupplierContext context,
6464
FormDataMapperOptions options,
65-
IReadOnlyDictionary<string, StringValues> form,
66-
FormOptions formOptions);
65+
IReadOnlyDictionary<string, StringValues> form);
6766
}
6867

6968
internal class FormValueSupplier<T> : FormValueSupplier
7069
{
7170
public override void Deserialize(
7271
FormValueSupplierContext context,
7372
FormDataMapperOptions options,
74-
IReadOnlyDictionary<string, StringValues> form,
75-
FormOptions formOptions)
73+
IReadOnlyDictionary<string, StringValues> form)
7674
{
7775
if (form.Count == 0)
7876
{
@@ -87,12 +85,12 @@ public override void Deserialize(
8785
{
8886
dictionary.Add(new FormKey(key.AsMemory()), value);
8987
}
90-
buffer = ArrayPool<char>.Shared.Rent(formOptions.KeyLengthLimit);
88+
buffer = ArrayPool<char>.Shared.Rent(options.MaxKeyBufferSize);
9189

9290
// Form values are parsed according to the culture of the request, which is set to the current culture by the localization middleware.
9391
// Some form input types use the invariant culture when sending the data to the server. For those cases, we'll
9492
// provide a way to override the culture to use to parse that value.
95-
var reader = new FormDataReader(dictionary, CultureInfo.CurrentCulture, buffer.AsMemory(0, formOptions.KeyLengthLimit))
93+
var reader = new FormDataReader(dictionary, CultureInfo.CurrentCulture, buffer.AsMemory(options.MaxKeyBufferSize))
9694
{
9795
ErrorHandler = context.OnError,
9896
AttachInstanceToErrorsHandler = context.MapErrorToContainer

src/Components/Endpoints/src/Binding/FormDataMapperOptions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
using System.Collections.Concurrent;
55
using System.Diagnostics.CodeAnalysis;
6+
using Microsoft.AspNetCore.Http.Features;
7+
using Microsoft.AspNetCore.WebUtilities;
68

79
namespace Microsoft.AspNetCore.Components.Endpoints.Binding;
810

@@ -31,6 +33,8 @@ public FormDataMapperOptions()
3133
// which is O(n).
3234
internal int MaxCollectionSize = 100;
3335

36+
internal int MaxKeyBufferSize = FormReader.DefaultKeyLengthLimit;
37+
3438
internal bool HasConverter(Type valueType) => _converters.ContainsKey(valueType);
3539

3640
internal bool IsSingleValueConverter(Type type)

src/Components/Endpoints/src/Binding/HttpContextFormDataProvider.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@ internal sealed class HttpContextFormDataProvider : FormDataProvider, IHostEnvir
1717

1818
public override IReadOnlyDictionary<string, StringValues> Entries => _entries ?? ReadOnlyDictionary<string, StringValues>.Empty;
1919

20-
public FormOptions FormOptions { get; private set; } = null!;
21-
22-
internal void SetFormOptions(FormOptions formOptions)
23-
{
24-
FormOptions = formOptions;
25-
}
26-
2720
void IHostEnvironmentFormDataProvider.SetFormData(string name, IReadOnlyDictionary<string, StringValues> form)
2821
{
2922
_name = name;

src/Components/Endpoints/src/Rendering/EndpointHtmlRenderer.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,6 @@ internal static async Task InitializeStandardComponentServicesAsync(
8888
if (handler != null && form != null && formData != null)
8989
{
9090
formData.SetFormData(handler, new FormCollectionReadOnlyDictionary(form));
91-
if (formOptions != null && formData is HttpContextFormDataProvider contextFormData)
92-
{
93-
contextFormData.SetFormOptions(formOptions);
94-
}
9591
}
9692

9793
// It's important that this is initialized since a component might try to restore state during prerendering

src/Components/Web/src/Forms/EditForm.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace Microsoft.AspNetCore.Components.Forms;
1212
public class EditForm : ComponentBase
1313
{
1414
private readonly Func<Task> _handleSubmitDelegate; // Cache to avoid per-render allocations
15+
private readonly RenderFragment _renderWithBindingValidator;
1516

1617
private EditContext? _editContext;
1718
private bool _hasSetEditContextExplicitly;
@@ -22,6 +23,7 @@ public class EditForm : ComponentBase
2223
public EditForm()
2324
{
2425
_handleSubmitDelegate = HandleSubmitAsync;
26+
_renderWithBindingValidator = RenderWithBindingValidator;
2527
}
2628

2729
/// <summary>
@@ -176,7 +178,7 @@ void RenderFormContents(RenderTreeBuilder builder, ModelBindingContext? bindingC
176178
builder.AddComponentParameter(7, "Value", _editContext);
177179
if (bindingContext != null && !OperatingSystem.IsBrowser())
178180
{
179-
builder.AddComponentParameter(8, "ChildContent", RenderWithBindingValidator());
181+
builder.AddComponentParameter(8, "ChildContent", _renderWithBindingValidator);
180182
}
181183
else
182184
{
@@ -187,14 +189,11 @@ void RenderFormContents(RenderTreeBuilder builder, ModelBindingContext? bindingC
187189
}
188190
}
189191

190-
private RenderFragment? RenderWithBindingValidator()
192+
private void RenderWithBindingValidator(RenderTreeBuilder builder)
191193
{
192-
return builder =>
193-
{
194-
builder.OpenComponent<ModelBindingContextValidator>(1);
195-
builder.CloseComponent();
196-
builder.AddContent(2, ChildContent!, EditContext);
197-
};
194+
builder.OpenComponent<ModelBindingContextValidator>(1);
195+
builder.CloseComponent();
196+
builder.AddContent(2, ChildContent!, EditContext);
198197
}
199198

200199
private async Task HandleSubmitAsync()

src/Components/Web/src/Forms/ValidationMessage.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ protected override void OnParametersSet()
5252
$"{nameof(For)} parameter.");
5353
}
5454
else if (For != _previousFieldAccessor)
55-
{
56-
55+
{
5756
_fieldIdentifier = FieldIdentifier.Create(For);
5857
_previousFieldAccessor = For;
5958
}

src/Components/Web/src/Microsoft.AspNetCore.Components.Web.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</PropertyGroup>
1414

1515
<ItemGroup>
16-
<Compile Include="$(ComponentsSharedSourceRoot)src\ExpressionFormatting\**\*" LinkBase="Forms\ExpressionFommatting" />
16+
<Compile Include="$(ComponentsSharedSourceRoot)src\ExpressionFormatting\**\*.cs" LinkBase="Forms\ExpressionFommatting" />
1717
</ItemGroup>
1818

1919
<ItemGroup>

src/Components/test/testassets/Components.TestServer/RazorComponents/Pages/Forms/CustomNumberInput.razor

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,6 @@
66
@code {
77
protected override bool TryParseValueFromString(string value, [MaybeNullWhen(false)] out int result, [NotNullWhen(false)] out string validationErrorMessage)
88
{
9-
if(int.TryParse(value, out result))
10-
{
11-
validationErrorMessage = null;
12-
return true;
13-
}else
14-
{
15-
// This is not used, since the error comes from the binding process.
16-
validationErrorMessage = "Not used.";
17-
return false;
18-
}
9+
throw new NotImplementedException();
1910
}
2011
}

0 commit comments

Comments
 (0)