From c3899acf797eb6779c53b313f5606c5018360b83 Mon Sep 17 00:00:00 2001 From: spinningtopsofdoom Date: Thu, 3 Mar 2016 17:13:41 -0600 Subject: [PATCH] LJS-1590: split, split-lines differs from Clojure on empty string Only discard training if split generates more than one element --- src/main/cljs/clojure/string.cljs | 2 +- src/test/cljs/cljs/core_test.cljs | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/cljs/clojure/string.cljs b/src/main/cljs/clojure/string.cljs index 37d1300e7a..4cf5ede115 100644 --- a/src/main/cljs/clojure/string.cljs +++ b/src/main/cljs/clojure/string.cljs @@ -119,7 +119,7 @@ (defn- discard-trailing-if-needed [limit v] - (if (== 0 limit) + (if (and (== 0 limit) (< 1 (count v))) (pop-last-while-empty v) v)) diff --git a/src/test/cljs/cljs/core_test.cljs b/src/test/cljs/cljs/core_test.cljs index d31e394cd4..5ac667b772 100644 --- a/src/test/cljs/cljs/core_test.cljs +++ b/src/test/cljs/cljs/core_test.cljs @@ -3132,6 +3132,12 @@ (is (= (hash-set Infinity -Infinity 0 1 2 3 4 5 6 7 8) (set (keys (zipmap [Infinity -Infinity 0 1 2 3 4 5 6 7 8] (repeat nil))))))) +(deftest test-cljs-1590 + (is (= [""] (s/split "" #"\n"))) + (is (= [] (s/split "\n\n\n" #"\n"))) + (is (= [""] (s/split-lines ""))) + (is (= [] (s/split-lines "\n\n\n")))) + (comment ;; ObjMap ;; (let [ks (map (partial str "foo") (range 500))