Forum OpenACS Development: Re: ad_quotehtml speed improvement

Collapse
Posted by Andrew Piskorski on
Hm, using string map does sound like a good idea, but you know, I just looked at the source code in AOLserver 3.3+ad13. ns_quotehtml is ultimiately implemented by Ns_QuoteHtml, and it definitely does quote double quotes. I suspect the ad_quotehtml docs above are very old - they probably date back to AOLserver 2.3.x, at which time presumably they were accurate.

In fact, Ns_QuoteHtml translates these 5 different characters to their equivalent HTML entitites:

<  >  &  \  "
each become, respectively:
&lt;  &gt;  &amp;  &#39;  &#34;

Note that ns_quotehtml is translating literal backslashes, while ad_quotehtml is not. Why or why not?

So while you're at it, it would also useful to compare the string map vs. ns_quotehtml performance. If they're similar I think string map should be preferred, as it's much more general and powerful, and avoids and unnecessary dependency on the Ns_QuoteHtml C code for anyone trying to use OpenACS Tcl procs outside of AOLserver.

Collapse
Posted by Dirk Gomez on
Shouldn't we rather try to reduce the overall amount of code and deprecate ad_quotehtml and recommend ns_quotehtml instead - if both do the same anyway?
Collapse
Posted by Daniël Mantione on
The discussion made me wonder why quotes need to be quoted...

The problem is, as far as I can see, the only reason why you would want to quote quotes, in within html-tags and especially links. But, at least within links, that is not correct at all... Why?

First example:

<A href='page?a=@a@&b=@b@'>

As you see, I'm using single quotes. This is perfectly legal, and often usefull because single quotes do not have any special meaning in Tcl. For example:

<%="
This is a text where some values like this one $var1 will be inserted automatically [funca]
<A href='page?a=${var2}&b=[funcb]'>blablbalbablablabl</A>
"%>

Because of this property, I've learned myself to write html using single quotes and so I can code adp like above in all my vanilla AOLserver code.

So, do we want to quote ' too? It would solve the problem.

Second example:

<%
# For simplicity of example, would normally be done in .tcl file
set name "Daniël Mantione"
%>
<A href='page?name=@name@'>blablablablablabla</A>

Whoops! Afaik, an URL should in all situation consist of standard US-Ascii. It is no solution to quote, &euml; won't work in a URL.

What should be done instead? This is, of course, ns_urlencode. This is true in any situation where a variable is being expanded within a tag attribute that specifies a URL. (I.e. A href, IMG src, LINK href etc...)

Unless there is another reason to quote ", the entire reason why it should be quoted is bogus...

Collapse
Posted by Andrew Piskorski on
Oops! My description above of Ns_QuoteHtml is incorrect! It does not quote backslash, it quotes single-quote. I mis-read the case '\'': in the C code last time around.

The Ns_QuoteHtml function appears to be identical in AOLserver 3.3+ad13 and the current AOLserver 4.0 CVS head.