aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2023-05-29 19:38:43 -0700
committerKaz Kylheku <kaz@kylheku.com>2023-05-29 19:38:43 -0700
commit10e1cc59ba222b463661fe01b0b783a2b8d49112 (patch)
treec903d0c95c61ce785faedd16fe27392e27b50e0e
parent271e541893c4d10b3b4fa8f20cb6c54f0af2527e (diff)
downloadtl-who-10e1cc59ba222b463661fe01b0b783a2b8d49112.tar.gz
tl-who-10e1cc59ba222b463661fe01b0b783a2b8d49112.tar.bz2
tl-who-10e1cc59ba222b463661fe01b0b783a2b8d49112.zip
New local macro noesc-fmt; fmt now escapes.
* packages.tl (tl-who): Add noesc-fmt symbol. * who.tl (with-html-output): Add escaping to fmt, which is disabled under *cl-who-compat*. Add noesc-fmt macro that looks like former definition of fmt. * test/simple.tl: New test cases 38-40. * README.md: Mention that TL-WHO provides noesc-fmt.
-rw-r--r--README.md2
-rw-r--r--packages.tl1
-rw-r--r--test/simple.tl19
-rw-r--r--who.tl8
4 files changed, 28 insertions, 2 deletions
diff --git a/README.md b/README.md
index b443472..53f99c5 100644
--- a/README.md
+++ b/README.md
@@ -181,6 +181,8 @@ Here are the differences to be aware of:
::text
(:a :href (noesc trusted-url) "click me")
+* TL-WHO provides a `noesc-fmt` which doesn't HTML-escape.
+
Additionally, users (of CL-WHO and TL-WHO alike) are advised to watch for the
following issue: the CL-WHO documentation is not accurately maintained and
makes some references to material that no longer exists in CL-WHO, such as the
diff --git a/packages.tl b/packages.tl
index 55c867c..8aa93d6 100644
--- a/packages.tl
+++ b/packages.tl
@@ -44,6 +44,7 @@
"html-mode"
"str"
"noesc"
+ "noesc-fmt"
"with-html-output"
"with-html-output-to-string"))
diff --git a/test/simple.tl b/test/simple.tl
index 7645901..3601814 100644
--- a/test/simple.tl
+++ b/test/simple.tl
@@ -430,3 +430,22 @@
(with-html-output-to-string (out)
(:foo :bar (noesc attr-val)))))
"<foo bar=''blah<tag>'></foo>")
+
+;;; 38
+;;; Test noesc-fmt
+(test (with-html-output-to-string (out)
+ (:foo (noesc-fmt "<a href=\"foo.html\">click</a>")))
+ "<foo><a href=\"foo.html\">click</a></foo>")
+
+;;; 39
+;;; Test that fmt escapes
+(test (with-html-output-to-string (out)
+ (:foo (fmt "<a href=\"foo.html\">click</a>")))
+ "<foo>&lt;a href=\"foo.html\"&gt;click&lt;/a&gt;</foo>")
+
+;;; 40
+;;; Test that fmt doesn't escape under *cl-who-compat*
+(test (expander-let ((*cl-who-compat* t))
+ (with-html-output-to-string (out)
+ (:foo (fmt "<a href=\"foo.html\">click</a>"))))
+ "<foo><a href=\"foo.html\">click</a></foo>")
diff --git a/who.tl b/who.tl
index 3c4a440..4d0c63d 100644
--- a/who.tl
+++ b/who.tl
@@ -240,12 +240,16 @@
(macrolet ((htm (. body)
^(with-html-output (,',var nil :prologue nil)
,*body))
- (fmt (. args)
+ (noesc-fmt (. args)
^(format ,',var ,*args))
+ (fmt (. args)
+ (if *cl-who-compat*
+ ^(noesc-fmt ,*args)
+ ^(put-string (html-encode* (usr:fmt ,*args)) ,',var)))
(esc (thing)
(with-gensyms (result)
^(whenlet ((,result ,thing))
- (put-string (html-encode ,result) ,',var))))
+ (put-string (html-encode* ,result) ,',var))))
(str (thing)
(with-gensyms (result)
^(whenlet ((,result ,thing))