11// Copyright (c) Six Labors.
22// Licensed under the Apache License, Version 2.0.
33
4+ using System ;
45using System . Collections . Generic ;
56using System . Linq ;
67using Microsoft . AspNetCore . Http ;
@@ -13,35 +14,40 @@ namespace SixLabors.ImageSharp.Web.Commands
1314 /// <summary>
1415 /// Parses preset name from the request querystring and returns the commands configured for that preset.
1516 /// </summary>
16- public class PresetRequestParser : IRequestParser
17+ public class PresetOnlyQueryCollectionRequestParser : IRequestParser
1718 {
1819 private readonly IDictionary < string , IDictionary < string , string > > presets ;
1920
2021 /// <summary>
21- /// Initializes a new instance of the <see cref="PresetRequestParser "/> class.
22+ /// Initializes a new instance of the <see cref="PresetOnlyQueryCollectionRequestParser "/> class.
2223 /// </summary>
2324 /// <param name="presetOptions">The preset options.</param>
24- public PresetRequestParser ( IOptions < PresetRequestParserOptions > presetOptions ) =>
25+ public PresetOnlyQueryCollectionRequestParser ( IOptions < PresetOnlyQueryCollectionRequestParserOptions > presetOptions ) =>
2526 this . presets = ParsePresets ( presetOptions . Value . Presets ) ;
2627
2728 /// <inheritdoc/>
2829 public IDictionary < string , string > ParseRequestCommands ( HttpContext context )
2930 {
30- var requestedPreset = context . Request . Query [ "preset" ] . ToString ( ) ;
31- return this . presets . GetValueOrDefault ( requestedPreset ) ?? new Dictionary < string , string > ( ) ;
31+ if ( context . Request . Query . Count == 0 )
32+ {
33+ return new Dictionary < string , string > ( StringComparer . OrdinalIgnoreCase ) ;
34+ }
35+
36+ var requestedPreset = context . Request . Query [ "preset" ] [ 0 ] ;
37+ return this . presets . GetValueOrDefault ( requestedPreset ) ?? new Dictionary < string , string > ( StringComparer . OrdinalIgnoreCase ) ;
3238 }
3339
3440 private static IDictionary < string , IDictionary < string , string > > ParsePresets (
3541 IDictionary < string , string > unparsedPresets ) =>
3642 unparsedPresets
3743 . Select ( keyValue =>
3844 new KeyValuePair < string , IDictionary < string , string > > ( keyValue . Key , ParsePreset ( keyValue . Value ) ) )
39- . ToDictionary ( keyValue => keyValue . Key , keyValue => keyValue . Value ) ;
45+ . ToDictionary ( keyValue => keyValue . Key , keyValue => keyValue . Value , StringComparer . OrdinalIgnoreCase ) ;
4046
4147 private static IDictionary < string , string > ParsePreset ( string unparsedPresetValue )
4248 {
4349 Dictionary < string , StringValues > parsed = QueryHelpers . ParseQuery ( unparsedPresetValue ) ;
44- var transformed = new Dictionary < string , string > ( parsed . Count ) ;
50+ var transformed = new Dictionary < string , string > ( parsed . Count , StringComparer . OrdinalIgnoreCase ) ;
4551 foreach ( KeyValuePair < string , StringValues > keyValue in parsed )
4652 {
4753 transformed [ keyValue . Key ] = keyValue . Value . ToString ( ) ;
0 commit comments