Closed Bug 338810 Opened 18 years ago Closed 18 years ago

HTML Comment Parsing

Categories

(Firefox :: General, defect)

PowerPC
macOS
defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 214476

People

(Reporter: darrenrobinson, Unassigned)

References

Details

Attachments

(2 files)

User-Agent:       Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.0.3) Gecko/20060426 Firefox/1.5.0.3
Build Identifier: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.0.3) Gecko/20060426 Firefox/1.5.0.3

There is an interesting error with the comment parsing within firefox; having read the details about 'valid' and 'invalid' comments in SGML/XML/HTML i am a little puzzled by the following:

i wrote a page and later was required to remove a script section for testing; the original script looked as follows:

<script language="JavaScript" type="text/javascript">
<!--
  // script content was here
//-->
</script>

to temporarily remove the script (for testing) i used the following:
<!--script language="JavaScript" type="text/javascript">
<!--
  // script content was here
//-->
</script-->

but soon found that many browsers see this as:
markup start [<!]
comment start [--]
comment content [script language="JavaScript" type="text/javascript"><!--// script content was here//]
comment end [--]
markup end [>]
markup start [<]
markup [/script]
erronious comment end [--]
markup end [>]

the last </script> is ignored as invalid markup (closed tag no start)

in order to combat this (for asthetic reasons - it not being significant to interpretation) i added the comment start <!-- to the begining of the script closing tag to produce the following:

markup start [<!]
comment start [--]
comment content [script language="JavaScript" type="text/javascript"><!--// script content was here//]
comment end [--]
markup end [>]
markup start [<!]
comment start [--]
comment content [/script]
comment end [--]
markup end [>]

after reading the documentation this MAY produce errors as it implies:
markup start [<!]
comment start [--]
comment content [script language="JavaScript" type="text/javascript"><!]
comment end [--]
markup [// script content was here//]
comment start [--]
comment content [><!]
comment end [--]
markup [/script]
comment start [--]
comment content [>]
...

the comment not being closed?!

firefox either interprets the original as follows:
markup start [<!]
comment start [--]
comment content [script language="JavaScript" type="text/javascript"><!--// script content was here//--></script]
comment end [--]
markup end [>]


the revised markup would therefore be interpreted by firefox as:
markup start [<!]
comment start [--]
comment content [script language="JavaScript" type="text/javascript"><!--// script content was here//--><!--/script]
comment end [--]
markup end [>]

which it isnt (an therefore i conclude this is NOT how firefox interprets comments)

the more probably interpretation for ther original by firefox is (through experimentation):
markup start [<!]
comment start [--]
comment content [script language="JavaScript" type="text/javascript"><!]
comment start (second level) [--]
comment content (second level) [// script content was here//]
comment end (second level) [--]
comment content [></script]
comment end [--]
markup end [>]

which means the following would be the result from the revised markup:

markup start [<!]
comment start [--]
comment content [script language="JavaScript" type="text/javascript"><!]
comment start (second level) [--]
comment content (second level) [// script content was here//]
comment end (second level) [--]
comment content [><!]
comment end [--]
markup [/script]
comment start [--]
comment content [>]
...

which is what is observed. this can be demonstrated by looking at the source as firefox sees it. comments in green match the above description.

However, this is still incorrect as there is no nesting of comments in HTML/XML/SGML

the correct interpretation is:
markup start [<!]
comment start [--]
comment content [script language="JavaScript" type="text/javascript"><!]
comment end [--]
markup [// script content was here//]
comment start [--]
comment content [></script]
comment end [--]
markup end [>]

which means the following would be the result from the revised markup:

markup start [<!]
comment start [--]
comment content [script language="JavaScript" type="text/javascript"><!]
comment end [--]
markup [// script content was here//]
comment start [--]
comment content [><!]
comment end [--]
markup [/script]
comment start [--]
comment content [>]
...

Reproducible: Always
*** Bug 338811 has been marked as a duplicate of this bug. ***
You can't nest comments, unfortunately.

From http://www.w3.org/TR/html401/intro/sgmltut.html#h-3.2.4 : 
"A common error is to include a string of hyphens ("---") within a comment.
Authors should avoid putting two or more adjacent hyphens inside comments."


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

Attachment

General

Created:
Updated:
Size: