473,324 Members | 2,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Split <SCRIPT> tags

Hi all,
I am using Tidy (C) for parsing html pages. I encountered a page that
has some script as follows:

<script>
....
var abc = "<script>some stuff here</" + "script>";
....
</script>

Tidy fails to parse this correctly. It ignores everything after the
script. As a result I lose the body and the links and all.
Is there any way I can correctly interpret a closing </scripttag as
the end of the script rather than trying to parse stuff inside the
script?

Thanks in advance!
B.

Jul 17 '06 #1
2 2927
bi**********@yahoo.com writes:
I am using Tidy (C) for parsing html pages. I encountered a page that
has some script as follows:

<script>
...
var abc = "<script>some stuff here</" + "script>";
This is trying to avoid "</script>" being seen as the end of the script.
Since browsers are more lenient than the HTML standard allows for,
they only end script element at "</script>". However, the standard
requires that the script element is ended at the first occurence of
"</".
The solution, as suggested in the HTML specification, is to break
up "<" and "/" like:
var abc = "<script>some stuff here<\/script>";
Tidy fails to parse this correctly.
That might also be the case, although I doubt it.

Without having access to Tidy or your page, I don't know what the
exact error might be. It might consider the nested <scriptan opening,
but that would be an error in parsing HTML, and I think Tidy should
be able to do that correctly.

More likely code occuring after the incorrect script closing above
causes Tidy to begin some other, unknown element, e.g.,:
if (x<y) ...
would look like the opening of a "y" element, and it is parsed as
HTML since it occours after the closing of the script element by the
first "</".
It ignores everything after the script. As a result I lose the body
and the links and all.
How does this "ignoring" show itself? What do you mean by "lose"?
Is there any way I can correctly interpret a closing </scripttag
as the end of the script rather than trying to parse stuff inside
the script?
The above fix for ending the script element correctly might help.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 17 '06 #2
This is trying to avoid "</script>" being seen as the end of the script.
Since browsers are more lenient than the HTML standard allows for,
they only end script element at "</script>". However, the standard
requires that the script element is ended at the first occurence of
"</".
The solution, as suggested in the HTML specification, is to break
up "<" and "/" like:
var abc = "<script>some stuff here<\/script>";
The page I am trying to parse is not my own page. Its from some other
site which I cannot modify. A sample page having the same structure is
this:
<html>

<head>
<title>Test for tidy</title>
</head>

<body>
<script type="text/javascript">
<!--
var d = "<script>this is within a nested script tag</"+"script>";
-->
</script>
<a href="1.html">This is link 1</a>
<a href="2.html">This is link 2</a>
<a href="3.html">This is link 3</a>
<a href="4.html">This is link 4</a>
<a href="5.html">This is link 5</a>

</body>

</html>
Without having access to Tidy or your page, I don't know what the
exact error might be. It might consider the nested <scriptan opening,
but that would be an error in parsing HTML, and I think Tidy should
be able to do that correctly.
The problem is that the <scripttag inside the quotes is treated as an
opening tag and the </scriptbefore the links is the closing tag. So
the outer <scriptnever gets closed. Tidy's cleaned up doc comes up
like this:
<html>
<head>
<meta name="generator" content=
"HTML Tidy for Windows (vers 14 February 2006), see www.w3.org">
<title>Test for tidy</title>
</head>
<body>
<script type="text/javascript">
<!--
var d = "<script>this is within a nested script
tag</"+"script>";
-->
<\/script>
<a href="1.html">This is link 1<\/a>
<a href="2.html">This is link 2<\/a>
<a href="3.html">This is link 3<\/a>
<a href="4.html">This is link 4<\/a>
<a href="5.html">This is link 5<\/a>

<\/body>

<\/html>
</script>
</body>
</html>

It ignores everything after the script. As a result I lose the body
and the links and all.

How does this "ignoring" show itself? What do you mean by "lose"?
As you can see above, by 'lose' I mean that the links are now a part of
the script tag and not the Body as they were earlier. I have code
further that extracts the text from the body, but in this case, since
its in the <scripttag, it gets 'lost'.
Is there any way I can correctly interpret a closing </scripttag
as the end of the script rather than trying to parse stuff inside
the script?

The above fix for ending the script element correctly might help.
Actually, I was thinking of modifying tidy code in some way to
completely ignore the script tags coz I dont need them at all.

Thanks.

Jul 17 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Madhav | last post by:
I have the following statements in my script. ---------------------------------------------------------- textToWrite = "<HTML> \n" + "<HEAD> \n" + "<TITLE>Calendar</TITLE> \n" + "<SCRIPT...
6
by: Mike Daniel | last post by:
I am attempting to use document.write(pageVar) that displays a new html page within a pop-up window and the popup is failing. Also note that pageVar is a complete HTML page containing other java...
1
by: D. Shane Fowlkes | last post by:
I'm a fairly skilled traditional ASP/VB programmer and am learning .NET. I was (recently) surprised to read in a book about declaring and defining all my page Functions in <script...
2
by: Jeffrey T. | last post by:
I had some JavaScript functions defined in the <SCRIPT> section at the top of an aspx page (tested fine there). I then moved the JavaScript functions to their own separate file and then...
1
by: andrew | last post by:
So I spent ages trying to work out what the problem was with my code when I did this and found a post which led me to the very simple solution. I use WebMatrix so I'm not sure if this is a major...
21
by: hemant.singh | last post by:
Hello all, I am try'g to send window.location.href to the server script who will generate dynamic javascript according to the referral name comg in as param Now bcz <script language="javascript"...
12
by: Iddo | last post by:
Hi, I am having a strange problem... I have an HTML file which has 2 script tags: 1) <script language="javascript" id="ABC" src="ABC.js" /> 2) <script id="general" language="javascript">...
44
by: rhythmace | last post by:
W3C HTML validator passes this: .... <script type="text/javascript" src="foo.js"> <script type="text/javascript"> ....script in here... </script> ....
4
by: Alex Maghen | last post by:
When I do this in my page... ClientScript.RegisterStartupScript(this.GetType(), "SomeScript", "alert(\"Hi there\");"); it doesn't work AND when I view source, the alert() line is dumped into the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.