unterminated string constant

Discussion in 'Javascript' started by aroraamit81@gmail.com, Dec 8, 2005.

  1. Guest

    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
    , Dec 8, 2005
    #1
    1. Advertising

  2. VK Guest

    wrote:
    > 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.
    VK, Dec 8, 2005
    #2
    1. Advertising

  3. Evertjan. Guest

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

    >
    > wrote:
    >> 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('');

    --
    Evertjan.
    The Netherlands.
    (Replace all crosses with dots in my emailaddress)
    Evertjan., Dec 8, 2005
    #3
  4. "VK" <> writes:

    > 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
    --
    Lasse Reichstein Nielsen -
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
    'Faith without judgement merely degrades the spirit divine.'
    Lasse Reichstein Nielsen, Dec 8, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?a2VuIHM=?=

    unterminated string constant

    =?Utf-8?B?a2VuIHM=?=, Oct 19, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    1,171
    Laurent Bugnion
    Oct 20, 2006
  2. Jeff
    Replies:
    4
    Views:
    130
    Richard Cornford
    May 7, 2004
  3. unterminated string constant

    , Dec 8, 2005, in forum: Javascript
    Replies:
    3
    Views:
    114
    Evertjan.
    Dec 8, 2005
  4. Tav
    Replies:
    2
    Views:
    106
    Thomas 'PointedEars' Lahn
    Jan 9, 2006
  5. William
    Replies:
    18
    Views:
    414
    Thomas 'PointedEars' Lahn
    Jan 25, 2006
Loading...

Share This Page