Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Unterminated String Constant

49 views
Skip to first unread message

Nathan Sokalski

unread,
Sep 1, 2009, 6:00:14 PM9/1/09
to
I have the following code in my page inside a script tag:

initRTE('<script language="JavaScript"
src="http://www.somedomain.com/polls/xlaabsolute.asp?p=32"></script>',
'example.css');

The first parameter of the JavaScript function is generated using Classic
ASP, so this is just the example I am using since I can't figure out whats
wrong. When I open the page in my browser, I recieve the error "Unterminated
String Constant". If I select Yes when asked whether I want to debug using
Visual Studio 2008, Visual Studio 2008 highlights/underlines the following
section of the above code:

'<script language="JavaScript"
src="http://www.somedomain.com/polls/xlaabsolute.asp?p=32"><

When I hover over this section of highlighted code in Visual Studio 2008, it
says "Unterminated String Constant" as well. I will probably feel pretty
stupid once I see the answer, but can somebody tell me why the string is
considered unterminated? Thanks.
--
Nathan Sokalski
njsok...@hotmail.com
http://www.nathansokalski.com/


Igor Tandetnik

unread,
Sep 1, 2009, 6:14:23 PM9/1/09
to
Nathan Sokalski <njsok...@hotmail.com> wrote:
> I have the following code in my page inside a script tag:
>
> initRTE('<script language="JavaScript"
> src="http://www.somedomain.com/polls/xlaabsolute.asp?p=32"></script>',
> 'example.css');

HTML parser doesn't understand JavaScript. When it encounters a <script>
tag, it looks through the rest of the text looking for </script>, takes
it as the closing tag, and passes everything in between to JavaScript
interpreter.

In your case, the </script> tag it finds happens to be inside a string
literal - but again, HTML parser doesn't know anything about JavaScript
or string literals.

A typical workaround goes something like this:

initRTE('<script language="JavaScript" src="',
'example.css">http://www.somedomain.com/polls/xlaabsolute.asp?p=32"></scr'
+ 'ipt>',
'example.css');

--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


Nathan Sokalski

unread,
Sep 1, 2009, 7:13:09 PM9/1/09
to
That would be great, except for the fact that, as I mentioned in my original
post, the first parameter of the function here is generated by a small piece
of Classic ASP (the value is coming from a database). What I really need is
to find a way to convert a value to a JavaScript String.

"Igor Tandetnik" <itand...@mvps.org> wrote in message
news:OzL1KI1K...@TK2MSFTNGP05.phx.gbl...

Bob Barrows

unread,
Sep 1, 2009, 10:03:26 PM9/1/09
to
So modify the ASP script to break up the string in the manner shown by Igor
... WTP?

Nathan Sokalski wrote:
> That would be great, except for the fact that, as I mentioned in my
> original post, the first parameter of the function here is generated
> by a small piece of Classic ASP (the value is coming from a
> database). What I really need is to find a way to convert a value to
> a JavaScript String.

--
Microsoft MVP - ASP/ASP.NET - 2004-2007
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


Nathan Sokalski

unread,
Sep 2, 2009, 9:59:55 PM9/2/09
to
The problem with doing that is that I do not know beforehand what the string
is, the string could be anything (and since whoever wrote the form that puts
the data in the database decided not to validate it, I really don't know
anything about the string). However, I finally found a solution online that
solved the problem. I basically modified the ASP to escape the single quotes
and forward slashes. The single quotes obviously need to be escaped because
they would look like the end of the string to JavaScript (I was actually
doing this from the beginning, but since there are no single quotes in this
example, it was irrelevant in this thread), and escaping the forward slashes
prevents the HTML parser from parsing what I don't want it to parse (please
excuse me if I incorrectly explained this, I'm not always good with words).
But whatever the reason, it is now working. Thank you everyone for your
help, I think the HTML parser thing is what helped point me in the right
direction to find the solution to my problem.

"Bob Barrows" <reb0...@NOyahoo.SPAMcom> wrote in message
news:eG9EQG3K...@TK2MSFTNGP05.phx.gbl...

Bob Barrows

unread,
Sep 3, 2009, 6:13:46 AM9/3/09
to
Nathan Sokalski wrote:
> The problem with doing that is that I do not know beforehand what the
> string is, the string could be anything (and since whoever wrote the
> form that puts the data in the database decided not to validate it, I
> really don't know anything about the string). However, I finally
> found a solution online that solved the problem. I basically modified
> the ASP to escape the single quotes and forward slashes. The single
> quotes obviously need to be escaped because they would look like the
> end of the string to JavaScript (I was actually doing this from the
> beginning, but since there are no single quotes in this example, it
> was irrelevant in this thread), and escaping the forward slashes
> prevents the HTML parser from parsing what I don't want it to parse
> (please excuse me if I incorrectly explained this, I'm not always
> good with words). But whatever the reason, it is now working. Thank
> you everyone for your help, I think the HTML parser thing is what
> helped point me in the right direction to find the solution to my
> problem.
0 new messages