|
| 1 | +using System.Globalization; |
1 | 2 | using Microsoft.AspNetCore.Http; |
2 | 3 | using Microsoft.AspNetCore.Http.Headers; |
3 | 4 | using Microsoft.Extensions.Options; |
@@ -47,20 +48,32 @@ public void Configure(ImageSharpMiddlewareOptions options) |
47 | 48 | return Task.CompletedTask; |
48 | 49 | } |
49 | 50 |
|
50 | | - var width = context.Parser.ParseValue<int>( |
51 | | - context.Commands.GetValueOrDefault(ResizeWebProcessor.Width), |
52 | | - context.Culture); |
53 | | - if (width <= 0 || width > _imagingSettings.Resize.MaxWidth) |
| 51 | + if (context.Commands.Contains(ResizeWebProcessor.Width)) |
54 | 52 | { |
55 | | - context.Commands.Remove(ResizeWebProcessor.Width); |
| 53 | + if (!int.TryParse( |
| 54 | + context.Commands.GetValueOrDefault(ResizeWebProcessor.Width), |
| 55 | + NumberStyles.Integer, |
| 56 | + CultureInfo.InvariantCulture, |
| 57 | + out var width) |
| 58 | + || width < 0 |
| 59 | + || width >= _imagingSettings.Resize.MaxWidth) |
| 60 | + { |
| 61 | + context.Commands.Remove(ResizeWebProcessor.Width); |
| 62 | + } |
56 | 63 | } |
57 | 64 |
|
58 | | - var height = context.Parser.ParseValue<int>( |
59 | | - context.Commands.GetValueOrDefault(ResizeWebProcessor.Height), |
60 | | - context.Culture); |
61 | | - if (height <= 0 || height > _imagingSettings.Resize.MaxHeight) |
| 65 | + if (context.Commands.Contains(ResizeWebProcessor.Height)) |
62 | 66 | { |
63 | | - context.Commands.Remove(ResizeWebProcessor.Height); |
| 67 | + if (!int.TryParse( |
| 68 | + context.Commands.GetValueOrDefault(ResizeWebProcessor.Height), |
| 69 | + NumberStyles.Integer, |
| 70 | + CultureInfo.InvariantCulture, |
| 71 | + out var height) |
| 72 | + || height < 0 |
| 73 | + || height >= _imagingSettings.Resize.MaxHeight) |
| 74 | + { |
| 75 | + context.Commands.Remove(ResizeWebProcessor.Height); |
| 76 | + } |
64 | 77 | } |
65 | 78 |
|
66 | 79 | return Task.CompletedTask; |
|
0 commit comments