Discussion:
ESC inside FMT doesn't get expanded
Leslie P. Polzer
2008-05-01 18:54:01 UTC
Permalink
Is this some kind of CL limitation?

Leslie
Edi Weitz
2008-05-01 19:35:45 UTC
Permalink
Post by Leslie P. Polzer
Is this some kind of CL limitation?
Not exactly sure what you mean (some example code would be helpful),
but it sounds as if you're expecting something that you shouldn't
expect.

Edi.
Leslie P. Polzer
2008-05-01 20:29:35 UTC
Permalink
Post by Edi Weitz
Not exactly sure what you mean (some example code would be helpful),
but it sounds as if you're expecting something that you shouldn't
expect.
I guess so, but I'm interested in the background.

Here's the case:

[4]> (in-package :cl-who)
#<PACKAGE CL-WHO>
WHO[5]> (with-html-output (*standard-output*)
(:p (fmt "~A" (esc "foo"))))
<p>
*** - EVAL: undefined function ESC

Leslie
Edi Weitz
2008-05-01 20:36:13 UTC
Permalink
Post by Leslie P. Polzer
[4]> (in-package :cl-who)
#<PACKAGE CL-WHO>
WHO[5]> (with-html-output (*standard-output*)
(:p (fmt "~A" (esc "foo"))))
<p>
*** - EVAL: undefined function ESC
Works as described:

http://weitz.de/cl-who/#syntax

The macro sees

(fmt "~A" (esc "foo"))

and substitutes

(format s "~A" (esc "foo"))

for it. At this point, CL-WHO stops expanding, and ESC is treated
like any other symbol.

Try this:

http://weitz.de/cl-who/#escape-string
Leslie P. Polzer
2008-05-02 06:29:49 UTC
Permalink
Post by Edi Weitz
At this point, CL-WHO stops expanding, and ESC is treated
like any other symbol.
The point for me is, why does it stop expanding?
It would be nice to have the ESC shortcut in this case.

Leslie
Osei Poku
2008-05-02 07:15:05 UTC
Permalink
Post by Leslie P. Polzer
Post by Edi Weitz
At this point, CL-WHO stops expanding, and ESC is treated
like any other symbol.
The point for me is, why does it stop expanding?
It would be nice to have the ESC shortcut in this case.
Why do you need to do that?

You don't need to escape after that point. You can just directly put
the string (or any other lisp expression) as the argument to fmt.

Osei
Leslie P. Polzer
2008-05-02 09:10:45 UTC
Permalink
Post by Osei Poku
Why do you need to do that?
You don't need to escape after that point. You can just directly put
the string (or any other lisp expression) as the argument to fmt.
Assume a malicious string ("<html>" in this case):

WHO[8]> (with-html-output (*standard-output*) (fmt "<~A>" "<html>"))
<<html>>
NIL
WHO[9]> (with-html-output (*standard-output*) (fmt "<~A>" (escape-string "<html>"))) <&lt;html&gt;>
NIL

Or did I misunderstand your question?

Leslie
Osei Poku
2008-05-02 13:36:05 UTC
Permalink
Post by Leslie P. Polzer
Post by Osei Poku
Why do you need to do that?
You don't need to escape after that point. You can just directly put
the string (or any other lisp expression) as the argument to fmt.
WHO[8]> (with-html-output (*standard-output*) (fmt "<~A>" "<html>"))
<<html>>
NIL
WHO[9]> (with-html-output (*standard-output*) (fmt "<~A>" (escape-
NIL
Why don't you use escape-string directly instead then? Like in your
example. Why use esc at all?
Leslie P. Polzer
2008-05-02 14:06:25 UTC
Permalink
Post by Osei Poku
Why don't you use escape-string directly instead then? Like in your
example. Why use esc at all?
It's shorter. When you use this function a lot (and I have to)
the lines tend to get long.

Plus, I don't think the behaviour in question is intuitive.

Leslie
Edi Weitz
2008-05-02 14:19:02 UTC
Permalink
It's shorter. When you use this function a lot (and I have to) the
lines tend to get long.
(defun esc (string)
(escape-string string))

Or use Arc...

Loading...