Skip to content

Bug: Skipping the elements while iterating with deletion operation #351

@RamanaReddy0M

Description

@RamanaReddy0M
package main

import (
	"fmt"

	mapsutil "github.com/projectdiscovery/utils/maps"
)

func main() {
	om := mapsutil.NewOrderedMap[string, string]()
	om.Set("offset", "0")
	om.Set("limit", "10")
	om.Set("sort", "desc")
	om.Set("cwe-id", "CWE-77")

	ignoreKeys := []string{"offset", "limit", "sort"}

	om.Iterate(func(key string, value string) bool {
		fmt.Println(key, value)
		for _, ignoreKey := range ignoreKeys {
			if key == ignoreKey {
				om.Delete(key)
				break
			}
		}
		return true
	})
}

Output:

offset 0
sort desc
cwe-id CWE-77
cwe-id CWE-77

Expected:

offset 0
limit 10
sort desc
cwe-id CWE-77

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions