diff --git a/src/ImageSharp.Web/Commands/PresetOnlyQueryCollectionRequestParser.cs b/src/ImageSharp.Web/Commands/PresetOnlyQueryCollectionRequestParser.cs index 6386ee7d..89042ac2 100644 --- a/src/ImageSharp.Web/Commands/PresetOnlyQueryCollectionRequestParser.cs +++ b/src/ImageSharp.Web/Commands/PresetOnlyQueryCollectionRequestParser.cs @@ -58,17 +58,13 @@ private static IDictionary ParsePresets( private static CommandCollection ParsePreset(string unparsedPresetValue) { - // TODO: Investigate skipping the double allocation here. - // In .NET 6 we can directly use the QueryStringEnumerable type and enumerate stright to our command collection - Dictionary parsed = QueryHelpers.ParseQuery(unparsedPresetValue); CommandCollection transformed = new(); - foreach (KeyValuePair pair in parsed) + foreach (QueryStringEnumerable.EncodedNameValuePair pair in new QueryStringEnumerable(unparsedPresetValue)) { - // Use the indexer for both set and query. This replaces any previously parsed values. - string? value = pair.Value[^1]; - if (value is not null) + // Last value wins. + if (pair.DecodeValue().Length > 0) { - transformed[pair.Key] = value; + transformed[pair.DecodeName().ToString()] = pair.DecodeValue().ToString(); } }