Skip to content

Commit

Permalink
escape function now uses contains? in place of includes?
Browse files Browse the repository at this point in the history
  • Loading branch information
weavejester committed Jun 2, 2009
1 parent bf29ba7 commit 860544f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/compojure/str_utils.clj
Expand Up @@ -16,10 +16,11 @@
"Returns a string with each occurance of a character in
chars escaped."
[chars #^String string]
(apply str
(mapcat
#(if (includes? chars %) [\\ %] [%])
string)))
(let [charset (set chars)]
(apply str
(mapcat
#(if (contains? charset %) [\\ %] [%])
string))))

(defn map-str
"Map a function to a collection, then concatenate the results into a
Expand Down
7 changes: 7 additions & 0 deletions test/compojure/str_utils.clj
@@ -0,0 +1,7 @@
(ns test.compojure.str-utils
(:use compojure.str-utils)
(:use clojure.contrib.test-is))

(deftest test-escape
(is (= (escape "aeiou" "hello world")
"h\\ell\\o w\\orld")))
2 changes: 2 additions & 0 deletions test/run.clj
Expand Up @@ -7,6 +7,7 @@
(:require test.compojure.http.response)
(:require test.compojure.http.session)
(:require test.compojure.http.helpers)
(:require test.compojure.str-utils)
(:require test.compojure.validation))

(run-tests
Expand All @@ -17,4 +18,5 @@
'test.compojure.http.response
'test.compojure.http.session
'test.compojure.http.helpers
'test.compojure.str-utils
'test.compojure.validation)

0 comments on commit 860544f

Please sign in to comment.