On 1/17/08, Matt Brock <[EMAIL PROTECTED]> wrote:
>
> Kalle Korhonen-2 wrote:
> > I needed to escape some strings pulled from database for Javascript, and
> > it
> > turned out to be surprisingly difficult. AFAIK, none of the
> Tapestry/Tacos
> > markup writers/character translators escapes a single quote '
> Well, that's because you don't necessarily have to escape the single
> quote.
> In javascript, these two are equivalent:
> alert('something'); // single quote
> alert("something else"); // double quote
Yes, and it's often very useful to take advantage of this -
e.gonclick="clickme('something')" - but it doesn't solve the problem.
If
"something" was an arbitrary string containing quotes or other special
characters, it'd still need to be escaped / safely encoded.
Also note, it's rather dangerous to assume a simple backslash will escape
> the string--it depends on the assumption that every JS field is using a
> particular quote (single or double). Much safer would be to use HTML
> entitites. This has been working for me...
If you read my sample, you'd see I was using an HTML entity reference.
Kalle