fsu.edu/~steele - JS handling of non-whitespace chars + "-->" on same line

RESOLVED INVALID

Status

RESOLVED INVALID
16 years ago
4 years ago

People

(Reporter: steele, Assigned: bc)

Tracking

unspecified

Details

(Whiteboard: (Special case: "--->" from bug 81935 ), URL)

Attachments

(1 attachment)

(Reporter)

Description

16 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.2b) Gecko/20021016
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.2b) Gecko/20021016

The following javascript code should display the lastModified time (works for
I.E. 6 and Netscape 6.2)

   <a href="http://validator.w3.org/check/referer">Valid XHTML 1.1 document</a>
   <script type="text/javaScript">
    <!-- /* <![CDATA[ */
    document.write(", last modified on " + document.lastModified);
    /* ]]> */ --> 
   </script>

NOTE: the line with "-->" is an error but still the line above it should have
been executed.  A LOT of old pages will not work right unless this is fixed.

Yes, I know that 
// ]]> --> 
will work.

Reproducible: Always

Steps to Reproduce:
1. go to http://ww2.cs.fsu.edu/~steele/Moz11ScriptBug.html
2. see that the date is NOT shown at bottom of page
3.

Actual Results:  
lastModified doate is not shown

Expected Results:  
show the date AND report the error with this line of code
 /* ]]> */ --> 


I commend you on the fine javascript engine you have, but rejecting
a script that begins with <!-- and end with --> is not good.  A LOT of old book
recommend this way of doing things and a lot of old pages do this.
Those old books also recommend putting those on separate lines.... but yes, we
should handle this better.
Assignee: jst → rogerl
Status: UNCONFIRMED → NEW
Component: DOM Level 0 → JavaScript Engine
Ever confirmed: true
OS: Windows XP → All
QA Contact: desale → pschwartau
Hardware: PC → All

Comment 2

16 years ago
For reference, here is a list of other bugs (some already resolved)
that include "-->" or "--->" in the summary:

bug 81935  ASSIGNED
JS doesn't ignore ---> in HTML (requires //--> or -->)
bug 312553 VERIFIED FIXED
JS doesn't ignore --> in HTML  (requires // -->)
bug 36122  VERIFIED DUP
--> makes invalidates script
bug 40625  VERIFIED DUP
JS doesn't ignore --> in HTML (requires // -->)

Comment 3

16 years ago
Let's try that again:

bug 81935  ASSIGNED
JS doesn't ignore ---> in HTML (requires //--> or -->)
bug 31255  VERIFIED FIXED
JS doesn't ignore --> in HTML  (requires // -->)
bug 36122  VERIFIED DUP
--> makes invalidates script
bug 40625  VERIFIED DUP
JS doesn't ignore --> in HTML  (requires // -->)

Comment 4

16 years ago
In the above list, bug 31255 is must reading. Don't miss it!!!

As a result of that fix, the HTML comment terminator --> was accepted
in JS as a single line comment indicator (e.g. like //). The same was
always true of the HTML multi-line comment opener <!-- . As a result,
this JS shell script will print "Hello" without error:

<!-- comment coment coment
print("Hello");
-->  comment coment coment


We permit whitespace before either <!-- or --> :

   <!-- comment coment coment
print("Hello");
   -->  comment coment coment


And we permit code before the <!-- :

1; <!-- comment coment coment
print("Hello");
-->  comment coment coment


The trouble occurs if there is any non-whitespace before the --> marker: 

<!-- comment coment coment
print("Hello");
1; -->  comment coment coment

produces the following error:

SyntaxError: syntax error:
1;  -->  comment coment coment
......^


Even /* */ triggers the same error if it appears before the --> marker: 

<!-- comment coment coment
print("Hello");
/* */ -->  comment coment coment


As Waldemar pointed out in bug 31255 Comment #10, we have to
be very careful about making --> into a comment marker if there
is code before it on the same line. Here is Waldemar's example:

var x = 10;
var y = 0;
while (x-->0)
  y += x;

Here, it would be disastrous to turn --> into a comment marker!


Of course, in my example I just had  1; -->
In the reporter's example it is  /* */  -->

So the question is, can we (or should we) make the JS parser
accept innocent things like that before --> on the same line?
Assignee: rogerl → khanson
Summary: javascript handling of trailing "-->" → JavaScript handling of trailing "-->"

Comment 5

16 years ago
Note the HTML comment opener <!-- is irrelevant to this bug. Both it and -->
are treated by SpiderMonkey as single-line comment indicators, not multi-line. 
Therefore I will leave it out.


IE6 BEHAVIOR:


----------------------------------------------------------------------------
alert("Hello");       alert("Hello");         alert("Hello");        
1; -->                1; --> comment          1; -->
                                              alert("Goodbye");
OUTPUT: "Hello"       OUTPUT: nothing         OUTPUT: nothing


----------------------------------------------------------------------------
alert("Hello");       alert("Hello");         alert("Hello");
/* */ -->             /* */ --> comment       /* */ -->
                                              alert("Goodbye");
OUTPUT: "Hello"       OUTPUT: nothing         OUTPUT: nothing


----------------------------------------------------------------------------
alert("Hello");       alert("Hello");         alert("Hello");
-->                   --> comment             -->
                                              alert("Goodbye");
OUTPUT: "Hello"       OUTPUT: nothing         OUTPUT: nothing



This shows that IE6 does not tolerate anything in the script
block appearing after -->, even if it is on a new line below it.

Mozilla currently yields the reported syntax error on the first six
examples here, but produces all requested alerts on the last three
(when nothing appears before the --> on the same line).

Comment 6

16 years ago
(Of course, ignore the hyperlink Bugzilla added to "comment          1")

*** This bug has been marked as a duplicate of 81935 ***
Status: NEW → RESOLVED
Last Resolved: 16 years ago
Resolution: --- → DUPLICATE

Comment 8

16 years ago
Reopening, unfortunately -

Bug 81935 has to do with our handling of "--->"
This bug: has to do with our handling of "-->"

Specifically, the problem here is how we handle "-->" if any
non-whitespace characters occur before it on the same line.

That makes bug 81935 a special case of this one, so any dupe should
be done against this one. I'd prefer to keep them both open, however.
Bug 81935 is a restricted case we might solve before the more general one.
Status: RESOLVED → REOPENED
Resolution: DUPLICATE → ---

Comment 9

16 years ago
Boris: thanks for pointing out the connection between these two bugs.
I'll resummarize this one accordingly -
Summary: JavaScript handling of trailing "-->" → JS handling of non-whitespace chars + "-->" on same line
Whiteboard: (Special case: "--->" from bug 81935 )
I'm ok with evang bugspam ;-).  Thanks for taking this one too.

/be
Assignee: khanson → bclary
Status: REOPENED → NEW
Component: JavaScript Engine → US General
Product: Browser → Tech Evangelism
Version: other → unspecified
(Assignee)

Comment 11

16 years ago
Created attachment 105465 [details]
revised test case

Shane, your test case is invalid. Please see the attached version which does
work as you expect.
(Assignee)

Updated

16 years ago
Status: NEW → ASSIGNED
QA Contact: pschwartau → susiew
Summary: JS handling of non-whitespace chars + "-->" on same line → fsu.edu/~steele - JS handling of non-whitespace chars + "-->" on same line
Target Milestone: --- → Nov
(Assignee)

Comment 12

16 years ago
invalid
Status: ASSIGNED → RESOLVED
Last Resolved: 16 years ago16 years ago
Resolution: --- → INVALID
Product: Tech Evangelism → Tech Evangelism Graveyard
You need to log in before you can comment on or make changes to this bug.