Unterminated string literal in JS

V

vunet.us

I have a function to open new window:
function bla(){ newwin = window.open("page.asp?file=1&id=<%=ID
%>","Image","other params") }

This function works fine mostly, but sometimes, there is a JavaScript
error: "Unterminated string literal". This happens only in one case.
If you noticed ASP variable <%=ID%>, then here's what happens to it.
ID gets url parameter "id" and inserts in that JavaScript. Obviously,
this URL comes from another page. And when it comes from the page with
someurl.asp?id=123%0%DA, then my JavaScript throws this error.
If previous page URL is just someurl.asp?id=123, then JS works
perfect. Where is the catch?
Thank you.
 
A

ASM

(e-mail address removed) a écrit :
I have a function to open new window:
function bla(){ newwin = window.open("page.asp?file=1&id=<%=ID
%>","Image","other params") }

This function works fine mostly, but sometimes, there is a JavaScript
error: "Unterminated string literal".

on which line of your code ?
with what browser ?
Obviously,
this URL comes from another page. And when it comes from the page with
someurl.asp?id=123%0%DA, then my JavaScript throws this error.

what does mean %0%DA ?
isn't it something missing ?
If previous page URL is just someurl.asp?id=123, then JS works
perfect.

However I tried with FF2 directly :
window.open("test.htm?file=1&id=%0%DA");
and ...
works fine
('id' has nonsense, but that works)
 
V

vunet.us

(e-mail address removed) a écrit :



on which line of your code ?
with what browser ?


what does mean %0%DA ?
isn't it something missing ?


However I tried with FF2 directly :
window.open("test.htm?file=1&id=%0%DA");
and ...
works fine
('id' has nonsense, but that works)

Browsers FF2 and IE7 tested. The same error.
Let's imagine I have a button "Edit Item", which has a hidden value
id=123. The id is taken from the url of this page, say, thispage.asp?
id=123. Form passes this id to anotherpage.asp which gets this id from
the form (with ASP: ID=request("id")) and inserts it into JS like
this:
function bla(){ newwin = window.open("thirdpage.asp?file=1&id=<%= ID
%>" ,"Image", "other params") }
This way it works. But if the same procedure is done starting with
page thispage.asp?id=123%0D%0A, error occurs as described above
"Unterminated string literal" and it even screws the following
functions in JS (they just do not exist).
Maybe I have to unescape url values or smth?
 
A

ASM

(e-mail address removed) a écrit :
This way it works. But if the same procedure is done starting with
page thispage.asp?id=123%0D%0A, error occurs as described above

Ha Ha ! it is not %0%DA as given previously
but ... %0D%0A

Anyway %0D or %0A to my idea can't exist
(%A0 or %D0 or %DA or %AD could be ok)

http://www.miakinen.net/vrac/charsets/
"Unterminated string literal" and it even screws the following
functions in JS

normal, on an error JS stops there.

Maybe I have to unescape url values or smth?

No, you have to correct you picking-up asp function

or to search which element in your form could give this value
(probably a character bad translated between iso-smth to/from utf-8 ?)
 
V

vunet.us

(e-mail address removed) a écrit :


Ha Ha ! it is not %0%DA as given previously
but ... %0D%0A

Anyway %0D or %0A to my idea can't exist
(%A0 or %D0 or %DA or %AD could be ok)

http://www.miakinen.net/vrac/charsets/


normal, on an error JS stops there.


No, you have to correct you picking-up asp function

or to search which element in your form could give this value
(probably a character bad translated between iso-smth to/from utf-8 ?)

are you saying that in ASP: ID=request("id") may obtain a bad value?
Sorry, i did not give the correct %0D%0A string in the first place.
 
R

Randy Webb

(e-mail address removed) said the following on 2/28/2007 4:39 PM:

are you saying that in ASP: ID=request("id") may obtain a bad value?

ASP may be giving a "good value" for ASP but the same value can be a
"bad value" for JS. Try having ASP escape the variable first.
 
A

ASM

(e-mail address removed) a écrit :
are you saying that in ASP: ID=request("id") may obtain a bad value?
Sorry, i did not give the correct %0D%0A string in the first place.

%0D%0A = \r\n in JS, that's to say a return carriage

document.getElementById('info').innerHTML = escape('123%0D%0A456');

gives

<pre id='info'>
123
456
</pre>

alert(typeof('123%0D%0A')); tells it's a string

Do not understand where string is unterminated.
 
V

vunet.us

(e-mail address removed) a écrit :


%0D%0A = \r\n in JS, that's to say a return carriage

document.getElementById('info').innerHTML = escape('123%0D%0A456');

gives

<pre id='info'>
123
456
</pre>

alert(typeof('123%0D%0A')); tells it's a string

Do not understand where string is unterminated.

the solution is unescape(<%=ItemID%>). thank you all for helping me. i
should have thought of this before...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,161
Messages
2,570,892
Members
47,430
Latest member
7dog123

Latest Threads

Top