From 39bb4745222f1545b19128eb516ff8966ebab7b7 Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Sat, 2 Aug 2025 23:37:52 -0400 Subject: [PATCH] Added fix for multivalued map. --- source/handy_http_primitives/multivalue_map.d | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/source/handy_http_primitives/multivalue_map.d b/source/handy_http_primitives/multivalue_map.d index 8567a6b..5762b57 100644 --- a/source/handy_http_primitives/multivalue_map.d +++ b/source/handy_http_primitives/multivalue_map.d @@ -183,17 +183,14 @@ struct MultiValueMap( * k = The key to remove. */ void remove(KeyType k) { + import std.algorithm : remove; long idx = indexOf(k); if (idx == -1) return; if (entries.length == 1) { clear(); return; } - if (idx + 1 < entries.length) { - const i = cast(size_t) idx; - entries[i .. $ - 1] = entries[i + 1 .. $]; - } - entries.length = entries.length - 1; + entries = entries.remove(idx); } /** @@ -446,3 +443,11 @@ unittest { builder.add("a", "456"); assert(builder.build()[] == [StringMultiValueMap.Entry("a", ["123", "456"])], builder.build().toString); } + +unittest { + MultiValueMap!(string, string) map; + map.add("a", "one"); + map.add("b", "two"); + map.add("c", "three"); + map.remove("a"); +}