Skip to content

Commit

Permalink
fixes #679
Browse files Browse the repository at this point in the history
  • Loading branch information
ikitommi committed Jun 30, 2024
1 parent ee67a74 commit 49e8d88
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
18 changes: 17 additions & 1 deletion modules/reitit-core/src/reitit/impl.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,28 @@
l m))]
(-path-vals [] [] m)))

(defn -copy-meta [to from]
(letfn [(-with-meta [x m]
(try (with-meta x m) (catch #?(:clj Exception, :cljs js/Error) _)))
(-copy [l p m]
(reduce-kv
(fn [l k v]
(let [p' (conj p k)
m' (meta (get-in from p'))]
(cond
(and m' (not (var? v))) (update-in l p' -with-meta m')
(and (map? v) (not (record? v)) (seq v)) (-copy l p' v)
:else l)))
l m))]
(-copy to [] to)))

(defn -assoc-in-path-vals [c]
(reduce (partial apply assoc-in) {} c))

(defn path-update [m path-map]
(-> (-path-vals m path-map)
(-assoc-in-path-vals)))
(-assoc-in-path-vals)
(-copy-meta m)))

(defn accumulator? [x]
(-> x meta ::accumulator))
Expand Down
8 changes: 8 additions & 0 deletions test/cljc/reitit/core_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -442,3 +442,11 @@
(deftest routing-bug-test-538
(let [router (r/router [["/:a"] ["/:b"]] {:conflicts nil})]
(is (nil? (r/match-by-path router "")))))

(deftest metadata-regression-679
(is (= ["/context/leaf" {:roles {:foo true}}]
(-> ["/context" {:roles {:foo false :bar true}}
["/leaf" {:roles ^:replace {:foo true}}]]
(r/router)
(r/routes)
(first)))))

0 comments on commit 49e8d88

Please sign in to comment.