From: Joel Holdbrooks Date: Mon, 29 Jul 2013 21:38:56 +0000 (-0700) Subject: Fix bug where empty strings could break tries X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=11fd73a88ca0140ee0d4baf099d477811ad595e4;p=frak.git Fix bug where empty strings could break tries --- diff --git a/src/frak.clj b/src/frak.clj index 035a09c..d26bc02 100644 --- a/src/frak.clj +++ b/src/frak.clj @@ -36,13 +36,11 @@ (visit trie)))) (defn- trie-put - ([s] - {:pre [(string? s)]} - (trie-put {} s)) + ([s] (trie-put {} s)) ([trie s] {:pre [(map? trie) (string? s)]} (if-not (seq s) - {} + trie (loop [t trie, ps (prefixes s)] (if-let [cs (and (next ps) (first ps))] (recur (grow t cs false) (next ps)) diff --git a/test/frak_test.clj b/test/frak_test.clj index 4f7b365..c3bae69 100644 --- a/test/frak_test.clj +++ b/test/frak_test.clj @@ -53,4 +53,9 @@ (is (not (or (re-matches pat1 "f") (re-matches pat1 "b") (re-matches pat1 "ba") - (re-matches pat1 "fo")))))) + (re-matches pat1 "fo"))))) + + (let [pat1 (pattern ["foo" "foot"]) + pat2 (pattern ["foo" "" "foot"])] + (is (= (str pat1) + (str pat2)))))