From 11fd73a88ca0140ee0d4baf099d477811ad595e4 Mon Sep 17 00:00:00 2001 From: Joel Holdbrooks Date: Mon, 29 Jul 2013 14:38:56 -0700 Subject: [PATCH] Fix bug where empty strings could break tries --- src/frak.clj | 6 ++---- test/frak_test.clj | 7 ++++++- 2 files changed, 8 insertions(+), 5 deletions(-) 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))))) -- 2.25.1