Skip to content

deep_remove removes keys that exist if final key does not exist#1

Description

@gorenje

Hi There,

Thank you for the lib, I was just about to roll my own and you saved me a bunch of time 馃憤

I think there is an error though and that is that deep_remove will remove the last known key if the full path does not exist.

Tried the following three examples:

Msg = #{k => #{k1 => #{k2 => value,k3 => #{k4 => value2},k4 => 333}}}.

mapz:deep_remove([k,k1,k2,k3,k4,k5], Msg).

#{k => #{k1 => #{k3 => #{k4 => value2},k4 => 333}}}

Here I want to remove a non-existent k5 but because k2 doesn't contain a k3, it's removed instead!

The actual example I tried was this:

%% same Msg as above
mapz:deep_remove([k,k1,k3,k4,k5], Msg).

#{k => #{k1 => #{k2 => value,k3 => #{},k4 => 333}}}

k3 contains a k4 but as k.k1.k3.k4 is not a map but a value (and does not contain a k5), k4 is removed instead of doing nothing - which I would assume to be the case for a non-existent path?

And the third example:

mapz:deep_remove([k,k33,k3,k4,k5], Msg).

${}

I can wipe my entire map by using a incorrect second key! :sadface:

Am I missing something?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions