Skip to content

Commit 9e94a79

Browse files
committed
CLJS-2537: Negative fractional index in contains? on array
1 parent 9979fea commit 9e94a79

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

src/main/cljs/cljs/core.cljs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,12 +1952,12 @@ reduces them without incurring seq initialization"
19521952
(-lookup o k not-found)
19531953

19541954
(array? o)
1955-
(if (and (some? k) (>= k 0) (< k (.-length o)))
1955+
(if (and (some? k) (< -1 k (.-length o)))
19561956
(aget o (int k))
19571957
not-found)
19581958

19591959
(string? o)
1960-
(if (and (some? k) (>= k 0) (< k (.-length o)))
1960+
(if (and (some? k) (< -1 k (.-length o)))
19611961
(.charAt o (int k))
19621962
not-found)
19631963

src/test/cljs/cljs/core_test.cljs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,6 +1537,14 @@
15371537
(deftest test-cljs-2457
15381538
(is (thrown-with-msg? js/Error #".* is not ISeqable" (seq #js {:a 1 :b 2}))))
15391539

1540+
(deftest test-cljs-2537
1541+
(is (true? (contains? (to-array [7 13 41]) -0.5)))
1542+
(is (== 7 (get (to-array [7 13 41]) -0.5)))
1543+
(is (== 7 (get (to-array [7 13 41]) -0.5 :not-found)))
1544+
(is (true? (contains? "ab" -0.5)))
1545+
(is (= \a (get "ab" -0.5)))
1546+
(is (= \a (get "ab" -0.5 :not-found))))
1547+
15401548
(deftest test-cljs-2549
15411549
(let [tap (fn [_])]
15421550
(add-tap tap)

0 commit comments

Comments
 (0)