Connecting Tech Pros Worldwide Forums | Help | Site Map

Unterminated string literal in JS

vunet.us@gmail.com
Guest
 
Posts: n/a
#1: Feb 28 '07
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.


ASM
Guest
 
Posts: n/a
#2: Feb 28 '07

re: Unterminated string literal in JS


vunet.us@gmail.com a écrit :
Quote:
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 ?
Quote:
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 ?
Quote:
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)

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
vunet.us@gmail.com
Guest
 
Posts: n/a
#3: Feb 28 '07

re: Unterminated string literal in JS


On Feb 28, 1:50 pm, ASM <stephanemoriaux.NoAd...@wanadoo.fr.invalid>
wrote:
Quote:
vunet...@gmail.com a écrit :
>
Quote:
I have a function to open new window:
function bla(){ newwin = window.open("page.asp?file=1&id=<%=ID
%>","Image","other params") }
>
Quote:
This function works fine mostly, but sometimes, there is a JavaScript
error: "Unterminated string literal".
>
on which line of your code ?
with what browser ?
>
Quote:
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 ?
>
Quote:
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)
>
--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
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?

ASM
Guest
 
Posts: n/a
#4: Feb 28 '07

re: Unterminated string literal in JS


vunet.us@gmail.com a écrit :
Quote:
On Feb 28, 1:50 pm, ASM <stephanemoriaux.NoAd...@wanadoo.fr.invalid>
wrote:
Quote:
>However I tried with FF2 directly :
> window.open("test.htm?file=1&id=%0%DA");
>and ...
>works fine
>('id' has nonsense, but that works)
Quote:
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/
Quote:
"Unterminated string literal" and it even screws the following
functions in JS
normal, on an error JS stops there.

Quote:
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 ?)



--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
vunet.us@gmail.com
Guest
 
Posts: n/a
#5: Feb 28 '07

re: Unterminated string literal in JS


On Feb 28, 4:01 pm, ASM <stephanemoriaux.NoAd...@wanadoo.fr.invalid>
wrote:
Quote:
vunet...@gmail.com a écrit :
>
Quote:
On Feb 28, 1:50 pm, ASM <stephanemoriaux.NoAd...@wanadoo.fr.invalid>
wrote:
Quote:
However I tried with FF2 directly :
window.open("test.htm?file=1&id=%0%DA");
and ...
works fine
('id' has nonsense, but that works)
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/
>
Quote:
"Unterminated string literal" and it even screws the following
functions in JS
>
normal, on an error JS stops there.
>
Quote:
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 ?)
>
--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
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.

Randy Webb
Guest
 
Posts: n/a
#6: Feb 28 '07

re: Unterminated string literal in JS


vunet.us@gmail.com said the following on 2/28/2007 4:39 PM:

<snip>
Quote:
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.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
ASM
Guest
 
Posts: n/a
#7: Mar 1 '07

re: Unterminated string literal in JS


vunet.us@gmail.com a écrit :
Quote:
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.

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
vunet.us@gmail.com
Guest
 
Posts: n/a
#8: Mar 2 '07

re: Unterminated string literal in JS


On Feb 28, 8:06 pm, ASM <stephanemoriaux.NoAd...@wanadoo.fr.invalid>
wrote:
Quote:
vunet...@gmail.com a écrit :
>
Quote:
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.
>
--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
the solution is unescape(<%=ItemID%>). thank you all for helping me. i
should have thought of this before...

Closed Thread


Similar JavaScript / Ajax / DHTML bytes