javascript ( <!-- and --> ) comments fails to mask embedded </script> tag

RESOLVED DUPLICATE of bug 32618

Status

()

Core
HTML: Parser
--
major
RESOLVED DUPLICATE of bug 32618
14 years ago
14 years ago

People

(Reporter: Randy Moore, Unassigned)

Tracking

Trunk
x86
Windows XP
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

14 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20040614 Firefox/0.9
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20040614 Firefox/0.9

I need to generate a new HTML page in a new window via JavaScript. The new page
also includes JavaScript. I do this by appending Javascript commands to a string
variable which I later write out to the new window. However, the Mozilla Parser
(unlike IE6 or Opera 7) will spot the "</script>" text within the string in the
line of code where I am assigning it to the string variable. This makes my
JavaScript code terminate prematurely, and the remaining JavaScript code is
instead rendered at the top of the (first) HTML page. With IE6 I can emulate
this behavior simply by removing the JavaScript comments ( <!-- --> ) that
separate my JavaScript code from the rest of the HTML code. So, this problem
seems to be related to Javascript comment tags not being able to properly mask
</script> tags when they are enclose in quotes (i.e. part of a string). You can
use the following code to replicate the problem:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <title>XML File Builder 1</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

    <script type="text/javascript" language="javascript">
    <!--

      function collectData()
      {
         var codeString = "<html><head><title>Add Link Data</title>";
         codeString += "<link rel='stylesheet' href='addData.css'
type='text/css' />";
         codeString += "<script language='javascript' type='text/javascript'
src='xmlDataTable.js'></script></head>";
         codeString += "</head><body><form id='myForm'><table>";
         codeString += "<tr><td>Name: </td><td><input type='text' id='name'
size='20' value=''/></td></tr>";
         codeString += "<tr><td>Category: </td><td><input type='text'
id='category' size='20' value=''/></td></tr>";
         codeString += "<tr><td>Description: </td><td><input type='text'
id='descript' size='50' value=''/></td></tr>";
         codeString += "<tr><td>URL: </td><td><input type='text' id='url'
size='50' value=''/></td></tr>";
         codeString += "</table><br/><button type='button' id='addRecord'
onclick='addRecord'>Add Record</button>";
         codeString += "</form></body></html>";

         myWindow1=window.open('','myWin1','left=250,top=250,height=299,width=480');
         myWindow1.document.write(codeString);
         myWindow1.focus();
      }

    // -->
    </script>
  </head>
  <body>
    <h3>XML File Builder</h3>
    <p>This script is designed to build XML data files that contain the link
data for my other script
    that generates the HTML code necessady to build a navigation menu.</p><hr/><br/>
    <button onclick="collectData();">Click here to begin</button>
  </body>
</html>





However, the Mozilla (& FireFox) HTML Parser is able to see the embedded
</script> tag (even when enclosed in quotes) 

Reproducible: Always
Steps to Reproduce:
1. Copy code example from 'Details' box above into text file and save as test.html
2. Load test.html file with IE6 or Opera to see how it should look and behave.
3. Load test.html file with Mozilla to see how it misbehaves.

Actual Results:  
The following text is displayed when test.html is rendered:

"; codeString += "
"; codeString += ""; codeString += ""; codeString += ""; codeString += "";
codeString += "
Name: 	
Category: 	
Description: 	
URL: 	

Add Record"; codeString += "
"; // For developmental purposes: var chrome =
"menubar,toolbar,status,location,scrollbars,resizable";
myWindow1=window.open('','myWin1','left=250,top=250,height=299,width=480,' +
chrome); myWindow1.document.write(codeString); myWindow1.focus(); } // -->
XML File Builder

Note: The graphic elements which I can not reproduce here include 4 text boxes
and two buttons.
This script is designed to build XML data files that contain the link data for
my other script that generates the HTML code necessady to build a navigation menu.

Expected Results:  
XML File Builder

This script is designed to build XML data files that contain the link data for
my other script that generates the HTML code necessady to build a navigation menu.

May be related to 

Bugzilla Bug 245348
"Comments inside <script> tags are closed (only) after the second </script> tag"

Not quite certain what this bug report means.

Comment 1

14 years ago
This sounds like bug 32618.

Comment 2

14 years ago
see bug 32618 comment 7

*** This bug has been marked as a duplicate of 32618 ***
Status: UNCONFIRMED → RESOLVED
Last Resolved: 14 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.