Forum OpenACS Q&A: misinterpreted \n from tcl / javascript

Hi all.

I'm in front of a pretty annoying problem.

Here is what I do :
1) fetching a multiple lines text from postgresql.
2) storing this text in a tcl variable in the .tcl
3) using this variable in a javascript function in the adp.

After 2), I use :
"set text [string map {\n \\n} $text]"

so that all end of lines are actually replaced by "\n" and javascript does not interpret the end of line as it is.

But that doesn't work. Inside the JS, using :
mailto:template_[@content.id@]="@text@";
will make a "Unterminated string literal" error.

The weird thing is that if I put @text@ somewhere in the adp, the browser will display the text like I want :
"some sweet text \nlike \nI want it".

And event worth, if I use inside JS :
mailto:template_[@content.id@]="some sweet text \nlike \nI want it";

It works ! :/

I'm lost, I don't know what's wrong and how to fix the problem.

Thanks for any advice

Collapse
Posted by Thomas Blanchin on
I forgot to mention that the @text@ variable comes from a multirow and is used inside a "multiple" tag

_javascript_
_multiple name="template_"_
mailto:template_[@content.id@]="@text@";
_/multiple_
...
_/javascript_

maybe it's good to know...

Collapse
Posted by Jon Griffin on
I just ran into that problem updating some of my documentation with xowiki. I emailed Gustaf, but now I am thinking it is either a CR problem or a templating problem.
It doesn't seem to like to quote @ or ::
Collapse
Posted by Thomas Blanchin on
I founded a quick fix :

adding :
set text [ad_text_to_html $text]
set text [ad_html_to_text $text]

before :
set text [string map {\n \\n} $text]

and that works... !?

Quite strange since ad_text_to_html and ad_html_to_text should result in the initial @text@ variable isn't it ?