From 10e1cc59ba222b463661fe01b0b783a2b8d49112 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 29 May 2023 19:38:43 -0700 Subject: 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. --- README.md | 2 ++ packages.tl | 1 + test/simple.tl | 19 +++++++++++++++++++ who.tl | 8 ++++++-- 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))))) "'>") + +;;; 38 +;;; Test noesc-fmt +(test (with-html-output-to-string (out) + (:foo (noesc-fmt "click"))) + "click") + +;;; 39 +;;; Test that fmt escapes +(test (with-html-output-to-string (out) + (:foo (fmt "click"))) + "<a href=\"foo.html\">click</a>") + +;;; 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 "click")))) + "click") 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)) -- cgit v1.2.3