Skip to content

Commit 8049469

Browse files
alexdowadswannodette
authored andcommitted
CLJS-889: re-pattern works on strings containing \u2028 or \u2029
JavaScript RegExps don't match \u2028 or \u2029 with ., which was causing the previous implementation of re-pattern to fail on those characters. (It was as if the regexp was chopped short at the point where the offending character appeared.)
1 parent 4228ee3 commit 8049469

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/cljs/cljs/core.cljs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8405,8 +8405,9 @@ reduces them without incurring seq initialization"
84058405
[s]
84068406
(if (instance? js/RegExp s)
84078407
s
8408-
(let [[_ flags pattern] (re-find #"^(?:\(\?([idmsux]*)\))?(.*)" s)]
8409-
(js/RegExp. pattern flags))))
8408+
(let [[prefix flags] (re-find #"^\(\?([idmsux]*)\)" s)
8409+
pattern (subs s (count prefix))]
8410+
(js/RegExp. pattern (or flags "")))))
84108411

84118412
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Printing ;;;;;;;;;;;;;;;;
84128413

test/cljs/cljs/core_test.cljs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,8 @@
937937
(is (= (re-seq (re-pattern "f(.)o") "foo bar foo baz foo zot") (list ["foo" "o"] ["foo" "o"] ["foo" "o"])))
938938
(is (= (re-matches (re-pattern "(?i)foo") "Foo") "Foo"))
939939
; new RegExp("").source => "(?:)" on webkit-family envs, "" elsewhere
940-
(is (#{"#\"\"" "#\"(?:)\""} (pr-str #"")))))
940+
(is (#{"#\"\"" "#\"(?:)\""} (pr-str #"")))
941+
(is (= (re-find (re-pattern "[\u2028]") " \u2028 ") "\u2028")))) ; regression test for CLJS-889
941942

942943
(deftest test-destructuring
943944
(testing "Testing destructuring"

0 commit comments

Comments
 (0)