Skip to content

Commit

Permalink
Preserve keyword namespaces in java-util-hashmappify-vals (#60)
Browse files Browse the repository at this point in the history
Without this patch, keys with different namespaces but equal names would non-deterministically
clobber each other. Also, namespaces may provide valuable context, so preserving them is generally
useful.
  • Loading branch information
DerGuteMoritz committed Nov 2, 2023
1 parent c035066 commit 33dda06
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/sentry_clj/core.clj
Expand Up @@ -27,8 +27,8 @@
on walk/stringify-keys."
[m]
(let [f (fn [[k v]]
(let [k (if (keyword? k) (name k) k)
v (if (keyword? v) (name v) v)]
(let [k (if (keyword? k) (str (symbol k)) k)
v (if (keyword? v) (str (symbol v)) v)]
(if (map? v) [k (HashMap. ^Map v)] [k v])))]
(walk/postwalk (fn [x] (if (map? x) (into {} (map f x)) x)) m)))

Expand Down
5 changes: 4 additions & 1 deletion test/sentry_clj/core_test.clj
Expand Up @@ -23,7 +23,10 @@
"everything is a string"
(expect {"a" "b"} (#'sut/java-util-hashmappify-vals {:a :b}))
(expect {"a" "b" {"c" "d"} (#'sut/java-util-hashmappify-vals {:a {:b {:c :d}}})})
(expect {"var1" "val1" "var2" {"a" {"b" {"c" {"d" {"e" "f"} "g" "h"}}}}} (#'sut/java-util-hashmappify-vals {:var1 "val1" :var2 {:a {:b {:c {:d {:e :f} :g :h}}}}}))))
(expect {"var1" "val1" "var2" {"a" {"b" {"c" {"d" {"e" "f"} "g" "h"}}}}} (#'sut/java-util-hashmappify-vals {:var1 "val1" :var2 {:a {:b {:c {:d {:e :f} :g :h}}}}})))
(expecting
"keyword namespaces are preserved"
(expect {"foo/qux" "some/value" "bar/qux" "another/value"} (#'sut/java-util-hashmappify-vals {:foo/qux :some/value :bar/qux :another/value}))))

(def event
{:event-id (UUID/fromString "4c4fbea9-57a7-4c99-808d-2284306e6c98")
Expand Down

0 comments on commit 33dda06

Please sign in to comment.