473,748 Members | 2,523 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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>so me 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 2970
bi**********@ya hoo.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>so me 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>so me 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/rasterTriangleD OM.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>so me 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>th is is within a nested script tag</"+"script>" ;
-->
</script>
<a href="1.html">T his is link 1</a>
<a href="2.html">T his is link 2</a>
<a href="3.html">T his is link 3</a>
<a href="4.html">T his is link 4</a>
<a href="5.html">T his 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>th is is within a nested script
tag</"+"script>" ;
-->
<\/script>
<a href="1.html">T his is link 1<\/a>
<a href="2.html">T his is link 2<\/a>
<a href="3.html">T his is link 3<\/a>
<a href="4.html">T his is link 4<\/a>
<a href="5.html">T his 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
2265
by: Madhav | last post by:
I have the following statements in my script. ---------------------------------------------------------- textToWrite = "<HTML> \n" + "<HEAD> \n" + "<TITLE>Calendar</TITLE> \n" + "<SCRIPT LANGUAGE=\"JavaScript1.2\"SRC=\"popWin.js\">"+ "</SCRIPT> \n" + "</HEAD> \n" + "<BODY> \n" ; textToWrite += "<\BODY>\n" +
6
12984
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 scripts. Being a javascript newbie and after significant testing, I suspect that the document.write fails after finding a </script> within pageVar. Does a trick exist that enables one to slightly alter pageVar whereby enabling...
1
1465
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 runat="server"></script> tags and these tags "should" be after the <html> tag but before the <body> tag. I'm used to writing all of my "logic" including functions, in block delimiter tags such as <% %> above the <html> tag. So, is my method now "old school"...
2
1553
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 referenced that file in the <HEAD> section of the aspx page. I then removed the <SCRIPT> section from the aspx page, and the JavaScript stopped working (it was getting called, but some functionality wasn't working). I verified the path and file name to...
1
1635
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 problem in VS or not but it is bloody frustrating. Stick the following bit of code into a page and save it. <%@ Page Language="C#" %>
21
8539
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" src="NO JAVASCRIPT CAN BE USED HERE" /> So I am see'g If I can use eval todo something what I am doing I have tried almost everything, following is being last one
12
62927
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"> function foo() { alert("aaa"); } </script>
44
2832
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
2226
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 HTML but with no <SCRIPT> block around it. Why would this be happening? Alex
0
8994
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8831
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9555
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9329
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8247
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4607
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4878
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3315
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.