Forum OpenACS Q&A: escaping strings

Posted by bill kellerman on
through looking at the code and noticing some slightly different styles to compare to my own, i have a simple question on the overhead of escaping quotation marks in strings.

the normal way:
[append output "<a href=\"file-list?path=$path\"] or even
[append output "<a href=file-list?path=$path>"]

they way that seems way easier to me:
[append output [subst {
    <a href="file-list?path=$path">test</a>
this way i can cut and paste html/text and never have to spend any time escaping characters.  this came about while trying to optimize storyserver's slothfull homebrew api.  it actually managed to speed things up quite a bit, and made html easier to manage for designers in our setup. there a performance hit for running subst on a string?  or for a page running a bunch of subst's on a bunch of text chunks requested by a bunch of people? vs regular slash substitution?

i'm lazy.  i hate having to do \" and \" every couple of lines.

2: Re: escaping strings (response to 1)
Posted by Peter Alberer on
why don´t you just use single quotes (') in your html? this way you need not escape anything. see
3: Re: escaping strings (response to 2)
Posted by Tilmann Singer on
Ideally you shouldn't construct html in the tcl code in the first place. If you follow this advice, the issue becomes less important because you have to build much fewer strings with quotes in them.


set list_url "file-list?[export_vars path]"


<a href="@list_url@">test</a>