diff --git a/AK/HashTable.h b/AK/HashTable.h index c9cfbabfa9..e961e75a0f 100644 --- a/AK/HashTable.h +++ b/AK/HashTable.h @@ -704,11 +704,12 @@ private: bucket.previous->next = bucket.next; else m_collection_data.head = bucket.next; - + bucket.previous = nullptr; if (bucket.next) bucket.next->previous = bucket.previous; else m_collection_data.tail = bucket.previous; + bucket.next = nullptr; } } diff --git a/Tests/AK/TestHashMap.cpp b/Tests/AK/TestHashMap.cpp index b7a284a8cd..8d46a3d612 100644 --- a/Tests/AK/TestHashMap.cpp +++ b/Tests/AK/TestHashMap.cpp @@ -201,3 +201,13 @@ TEST_CASE(basic_contains) EXPECT_EQ(map.remove(1), true); EXPECT_EQ(map.contains(1), false); } + +TEST_CASE(in_place_rehashing_ordered_loop_bug) +{ + OrderedHashMap map; + map.set("yt.innertube::nextId", ""); + map.set("yt.innertube::requests", ""); + map.remove("yt.innertube::nextId"); + map.set("yt.innertube::nextId", ""); + VERIFY(map.keys().size() == 2); +}