Skip to content

Commit 7dc3e5c

Browse files
committed
Update to Java commit e0ac2d7 (2020-12-11): CLJ-2585 - Fix index check in nth with not-found for regex matcher
1 parent 2498028 commit 7dc3e5c

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Clojure/Clojure.Tests/clojure/test_clojure/other_functions.clj

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,19 @@
348348
; Regex Support
349349
; re-matcher re-find re-matches re-groups re-seq
350350

351+
(deftest test-regex-matcher
352+
(let [matcher (re-matcher #"(\d{2})/(\d{2})/(\d{4})" "12/02/1975")]
353+
(is (= ["12/02/1975" "12" "02" "1975"] (re-find matcher)))
354+
(is (= ["12/02/1975" "12" "02" "1975"] (re-groups matcher)))
355+
(is (= "12/02/1975" (nth matcher 0) (nth matcher 0 :foo)))
356+
(is (= "12" (nth matcher 1) (nth matcher 1 :foo)))
357+
(is (= "02" (nth matcher 2) (nth matcher 2 :foo)))
358+
(is (= "1975" (nth matcher 3) (nth matcher 3 :foo)))
359+
(is (thrown? ArgumentOutOfRangeException (nth matcher -1))) ;;; IndexOutOfBoundsException
360+
(is (= :foo (nth matcher -1 :foo)))
361+
(is (thrown? ArgumentOutOfRangeException (nth matcher 4))) ;;; IndexOutOfBoundsException
362+
(is (= :foo (nth matcher 4 :foo)))))
363+
351364
; update
352365

353366
(deftest test-update

Clojure/Clojure/Lib/RT.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,8 @@ static object NthFrom(object coll, int n, object notFound)
11361136
{
11371137
if (jrem.IsUnrealizedOrFailed)
11381138
return notFound;
1139-
if (n < jrem.groupCount())
1139+
int groups = jrem.groupCount();
1140+
if (groups > 0 && n <= jrem.groupCount())
11401141
return jrem.group(n);
11411142
return notFound;
11421143
}

0 commit comments

Comments
 (0)