unterminated string constant

A

aroraamit81

Hi,

I am facing a problem in javascript. strdata is a variable of
javascript and following is an assignment( hmmmmmmmmmmm a Huge one but
unfortunately its not mine code, I am just trying to rectify it) to
this varibale.. Now I am facing a run time error(Unterminated string
constant). Can any one please help me solving this bug.


strdata +="<tr <% if functionality_add = 0 and functionality_edit = 0
and functionality_delete = 0 then %>style='visibility:hidden'<% end if
%>><td valign=top colspan=2 class='formField' height='25'
style='display:none' id='R_F" +curNode.item(0).text + "'><% if
functionality_add <> 0 or functionality_edit <> 0 then %>Sub Region /
City: <% end if %><font color='#FF0000' size='2'>*</font>&nbsp;<input
size='40' class='inputBox' maxlength='200' type='text'
name='city_"+curNode.item(0).text +"'<% if functionality_add = 0 and
functionality_edit = 0 then %>style='visibility:hidden'<% end if
%>>&nbsp;<select name='reg_type_"+curNode.item(0).text
+"'class='drpdwn' <% if functionality_add = 0 and functionality_edit =
0 then %>style='visibility:hidden'<% end if %>><option value=1>Sub
Region</option><option value=2>City</option></select><input class='Btn'
type=button name='addBtn2_"+curNode.item(0).text+"' value='Add'
onClick='submit_form(2)'" <% if functionality_add = 0 then
%>"style='visibility:hidden'" <% end if %>><input class='Btn'
type=button value='Edit' name='edBtn2_"+curNode.item(0).text+"'
onclick='gotoEditMode_2(" +curNode.item(0).text + ")' disabled <% if
functionality_edit = 0 then %>style='visibility:hidden' <% end if
%>><input width=75 disabled name='delBtn2_"+curNode.item(0).text+"'
type='button' class='Btn' value='Delete' onclick='delregion(2)' <% if
functionality_delete = 0 then %>style='visibility:hidden' <% end if
%></td></tr>"

Regards,
Amit Arora
 
V

VK

Hi,

I am facing a problem in javascript. strdata is a variable of
javascript and following is an assignment( hmmmmmmmmmmm a Huge one but
unfortunately its not mine code, I am just trying to rectify it) to
this varibale.. Now I am facing a run time error(Unterminated string
constant). Can any one please help me solving this bug.

It is not a bug: new line cannot be used inside of a string literal.

The conventional way for long literals is:

var str = "";
str+= "hhhhhhhhhhhhhhhhhhhhhh";
str+= "uuuuuuuuuuuuuuuuuuuuuu";
str+= "gggggggggggggggggggggg";
str+= "eeeeeeeeeeeeeeeeeeeeee";

There is also a native (means common for all JavaScript/JScript
implementations) model failure exploit which allows you to do things
like:
(Google news swallows the backslashes, so instead of a real one I'm
using [backslash] marker)

var str = "[backslash]
hhhhhhhhhhhhhhhhhhhhhh[backslash]
uuuuuuuuuuuuuuuuuuuuuu[backslash]
gggggggggggggggggggggg[backslash]
eeeeeeeeeeeeeeeeeeeeee";

Note that [backslash] must to be the last char in the string. Also as
any exploit it is not guranteed to stay forever.
 
E

Evertjan.

VK wrote on 08 dec 2005 in comp.lang.javascript:
Hi,

I am facing a problem in javascript. strdata is a variable of
javascript and following is an assignment( hmmmmmmmmmmm a Huge one but
unfortunately its not mine code, I am just trying to rectify it) to
this varibale.. Now I am facing a run time error(Unterminated string
constant). Can any one please help me solving this bug.

It is not a bug: new line cannot be used inside of a string literal.

The conventional way for long literals is:

var str = "";
str+= "hhhhhhhhhhhhhhhhhhhhhh";
str+= "uuuuuuuuuuuuuuuuuuuuuu";
str+= "gggggggggggggggggggggg";
str+= "eeeeeeeeeeeeeeeeeeeeee";

There is also a native (means common for all JavaScript/JScript
implementations) model failure exploit which allows you to do things
like:
(Google news swallows the backslashes, so instead of a real one I'm
using [backslash] marker)

var str = "[backslash]
hhhhhhhhhhhhhhhhhhhhhh[backslash]
uuuuuuuuuuuuuuuuuuuuuu[backslash]
gggggggggggggggggggggg[backslash]
eeeeeeeeeeeeeeeeeeeeee";

Note that [backslash] must to be the last char in the string. Also as
any exploit it is not guranteed to stay forever.

var str =
'hhhhhhhhhhhhhhhhhhhhhh'+
'uuuuuuuuuuuuuuuuuuuuuu'+
'gggggggggggggggggggggg'+
'eeeeeeeeeeeeeeeeeeeeee';

var str =
'hhhhhhhhhhhhhhhhhhhhhh'
+'uuuuuuuuuuuuuuuuuuuuuu'
+'gggggggggggggggggggggg'
+'eeeeeeeeeeeeeeeeeeeeee';

var str = ''.concat(
'hhhhhhhhhhhhhhhhhhhhhh',
'uuuuuuuuuuuuuuuuuuuuuu',
'gggggggggggggggggggggg',
'eeeeeeeeeeeeeeeeeeeeee');

var str = [
'hhhhhhhhhhhhhhhhhhhhhh',
'uuuuuuuuuuuuuuuuuuuuuu',
'gggggggggggggggggggggg',
'eeeeeeeeeeeeeeeeeeeeee']
..join('');
 
L

Lasse Reichstein Nielsen

VK said:
There is also a native (means common for all JavaScript/JScript
implementations)

That's a broad sweep :)
model failure exploit which allows you to do things like:
(Google news swallows the backslashes, so instead of a real one I'm
using [backslash] marker)

var str = "[backslash]
hhhhhhhhhhhhhhhhhhhhhh[backslash]
uuuuuuuuuuuuuuuuuuuuuu[backslash]
gggggggggggggggggggggg[backslash]
eeeeeeeeeeeeeeeeeeeeee";

While it might work in most Javascript implementations, what it means
is different. In some browsers, the "backslash newline" is not in the
resulting string (e.g., IE, Opera and Mozilla), in others the newline
itself is escaped and occurs in the string (e.g., Netscape 4).

/L
 

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
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top