Browse files

c.c.prxml: Fix bad refers from lazy-xml

  • Loading branch information...
1 parent c8be496 commit 7a0e744c9f40280f1f28619102fe9f7dfb05401a @stuartsierra stuartsierra committed Feb 11, 2010
Showing with 21 additions and 6 deletions.
  1. +11 −6 src/main/clojure/clojure/contrib/prxml.clj
  2. +10 −0 src/test/clojure/clojure/contrib/test_prxml.clj
View
17 src/main/clojure/clojure/contrib/prxml.clj
@@ -27,7 +27,8 @@
:doc "Compact syntax for generating XML. See the documentation of \"prxml\"
for details."}
clojure.contrib.prxml
- (:use [clojure.contrib.lazy-xml :only (escape-xml)]))
+ (:use [clojure.contrib.string :only (escape)]
+ [clojure.contrib.java :only (as-str)]))
(def
#^{:doc "If true, empty tags will have a space before the closing />"}
@@ -38,16 +39,20 @@ for details."}
and no extra line-breaks."}
*prxml-indent* nil)
-(defn- namestr [x]
- (if (or (symbol? x) (keyword? x)) (name x) (str x)))
-
(def #^{:private true} *prxml-tag-depth* 0)
(def #^{:private true} print-xml) ; forward declaration
+(defn- escape-xml [s]
+ (escape {\< "&lt;"
+ \> "&gt;"
+ \& "&amp;"
+ \' "&apos;"
+ \" "&quot;"} s))
+
(defn- prxml-attribute [name value]
(print " ")
- (print (namestr name))
+ (print (as-str name))
(print "=\"")
(print (escape-xml (str value)))
(print "\""))
@@ -88,7 +93,7 @@ for details."}
(print ">"))
(defmethod print-xml-tag :default [tag attrs contents]
- (let [tag-name (namestr tag)]
+ (let [tag-name (as-str tag)]
(when *prxml-indent*
(newline)
(dotimes [n (* *prxml-tag-depth* *prxml-indent*)] (print " ")))
View
10 src/test/clojure/clojure/contrib/test_prxml.clj
@@ -0,0 +1,10 @@
+(ns clojure.contrib.test-prxml
+ (:use clojure.test clojure.contrib.prxml))
+
+(deftest prxml-basic
+ (is (= "<p>Hello, World!</p>"
+ (with-out-str (prxml [:p "Hello, World!"])))))
+
+(deftest prxml-escaping
+ (is (= "<a href=\"foo&amp;bar\">foo&lt;bar</a>"
+ (with-out-str (prxml [:a {:href "foo&bar"} "foo<bar"])))))

0 comments on commit 7a0e744

Please sign in to comment.