0

I'm trying to embed some code between <script> </script> tags, pyramid however doesn't like it and gives me

ExpatError: not well-formed (invalid token)

Probably because i have && in my code. I tried using &amp; instead, but then it didn't get interpreted in the browser.

The same thing happens when i try to put it in CDATA block.

When I move the code to a separate js file it works. I'd like to keep it in the same file for now, just to enable quick corrections.

So, how should I do it?

EDIT:

I get the same error even for templates as simple as this one:

<html
    xmlns:tal="http://xml.zope.org/namespaces/tal"
    xmlns:metal="http://xml.zope.org/namespaces/metal">
    <head>
    </head>
    <body>
        <span onclick="alert(true && false);">test</span>
    </body>
 </html>
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
soulcheck
  • 36,297
  • 6
  • 91
  • 90

4 Answers4

1

I think you're supposed to put && (i.e. two times the HTML entity code).

malthe
  • 1,237
  • 13
  • 25
1

This should work:

<script type="text/javascript">
    //<![CDATA[
        // my javascript
    //]]>
</script>
tshepang
  • 12,111
  • 21
  • 91
  • 136
pire
  • 11
  • 1
0

Have you tried adding a type attribute to your script tag?:

<script type="text/javascript">
...
</script>
Shad
  • 15,134
  • 2
  • 22
  • 34
  • Have you tried escaping the ampersands? `alert(true \&\& false);` I've experienced an issue like this with with curly brackets and Smarty – Shad Mar 03 '11 at 19:10
  • there should be some kind of a switch to turn off validation, but its really strange it doesn't work out of the box. – soulcheck Mar 03 '11 at 19:16
  • That's annoying. =( With Smarty, for instance, `{` is a reserved character in templates, and so on-page Style tags `body {font-size:12px;}` are just completely illegal and have to be externalized...~ – Shad Mar 03 '11 at 19:29
  • and very off-putting, especially when just starting a project :/ – soulcheck Mar 03 '11 at 19:39
0

It looks like xhtml issue, as w3c validator reported the same error.

I was thinking if there's a switch to change the document type parsed by chameleon to html, but then it wouldn't be possible to include tal and metal namespaces.

Hence it is expected behavior

soulcheck
  • 36,297
  • 6
  • 91
  • 90