Closed Bug 441438 Opened 16 years ago Closed 16 years ago

browser reports "xml parse error: not well formed" when encountering a '<' character as part of a javascript expression

Categories

(Firefox :: General, defect)

All
Linux
defect
Not set
major

Tracking

()

RESOLVED INVALID

People

(Reporter: journeyman_5150, Unassigned)

Details

User-Agent:       Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9) Gecko/2008061712 Fedora/3.0-1.fc9 Firefox/3.0
Build Identifier: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9) Gecko/2008061712 Fedora/3.0-1.fc9 Firefox/3.0

Entered the following code:
var dork = 0;
if(dork < 1) {
  alert("You're a dork");
}
Reports an xml parsing error here:
         if(dork < 1) {
------------------^

If I change the "<" to a ">", the parse error disappears

Reproducible: Always

Steps to Reproduce:
1.Enter the code in Details
2.?!?!
3.Profit!
(no seriously, it's an xhtml 1.1 document using the xml namespace (and the svg namespace, although the error occurs independently of it), and the error occurs in a <script language="JavaScript"> tag in the head tag of the document.  I'd been cranking along with a lot of JS code just fine before this error.
Actual Results:  
xml parse error

Expected Results:  
successful parse

Don't think it's relevant, but I'd be happy to supply the buildconfig if you need it.
Not a bug.  RTFM:
http://www.w3schools.com/XML/xml_cdata.asp

If your JavaScript is inside an XML document, it cannot have '<' or '>' in it, as those signify XML markup.  Enclose the whole script block in a CDATA element to get the XML parser to not parse the non-XML.
Status: UNCONFIRMED → RESOLVED
Closed: 16 years ago
Resolution: --- → INVALID
Your example would then be:
<script language="JavaScript">
<![CDATA[
var dork = 0;
if(dork < 1) {
  alert("You're a dork");
}
]]>
</script>

'>' and '&' can't be used in JavaScript like this without the CDATA around it.
You need to log in before you can comment on or make changes to this bug.