W3C home > Mailing lists > Public > html-tidy@w3.org > April to June 2000

Minor <script> problem

From: Pete Gelbman <pete@arraycomm.com>
Date: Fri, 05 May 2000 23:32:50 +0800
Message-Id: <200005051532.XAA03283@isaiah.arraycomm.com>
To: html-tidy@w3.org
cc: Sebastian Lange <lange@cyperfection.de>

I stumbled across an issue with <script> elements, while using Tidy to parse 
incomplete HTML code that I have embedded within Server-Side-Include 
applications. These are Perl CGI scripts that output HTML that in turn have 
embedded JavaScript code. I know this isn't exactlty an off-the shelf function 
of Tidy, but I beleive it unearthed something worth looking into:

Basic issue:
Tidy may place <script> elements in a location not intended by the author if 
the they are incorrectly located in the source file.

Section 18.2 of the w3c HTML4.01 spec says this:

"The SCRIPT element places a script within a document. This element may appear 
any number of times in the HEAD or BODY of an HTML document."

- OK, so scripts can go in both places. Normally people put non-executing JS 
code (functions) within <script> elements located in HEAD, and place JS 
statements/function calls within <script> elements located in BODY.

Problem I'm seeing with Tidy:
When <script> tags are properly located within HEAD or BODY, alls well: 
<script> elements within BODY stay there, and those within HEAD stay there too.

However, if <script> tags are improperly located outside of these 2 areas, 
(outside of HEAD & BODY) Tidy puts them where it wants, which may or *MAY NOT* 
be where the author orignially intended:

Case #1:

If the source file has no valid BODY tags, Tidy automatically puts any <script>
 tags in HEAD.

- Maybe the author really wanted the <script> tags to go in BODY, but goofed 
on his BODY html syntax?

Case #2:

If the source file has no valid HEAD, but BODY is present, then same thing as 
above; Tidy stuffs <script> elements within HEAD.

- So once again, what if the author intended his <script> elements to be in 
BODY but this time goofed on his HEAD html syntax?


I deal with lots of SSI/CGI's so this became painful for me. Sebastian Lange 
and myself are working on Perl solutions for running Tidy the way we need for 
our specific applications.

However, I think Tidy should properly deal with this too, no?

Per W3C, <script> elements can go in either HEAD or BODY. Perhaps in the 
future Tidy could have a option to let the user configure a default HEAD/BODY 
location for incorrectly placed <script> elements, and generate a warning 
message telling the user where they got put?

thats my .02


Received on Friday, 5 May 2000 11:49:42 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:38:47 UTC