Problem using "<script>" as a string in script!


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Problem using "<script>" as a string in script!

  1. #1
    Richard Berman Guest

    Problem using "<script>" as a string in script!


    OK, I'm bewildered. If what I'm seeing is true, then dozens of sample programs
    wouldn't work. Let me tell you what I see.

    IIS 5, Win2K Server SP2, Visual Studio 6 SP5 (including InterDev). 750MHz,
    512MB RAM, lots of disk space.

    I have a server-side script block (this was done both in VBScript and JavaScript).
    I wanted it to look like so:

    <SCRIPT ID=serverEventHandlersJS LANGUAGE=javascript RUNAT=Server>

    function thisPage_onshow() {
    Response.Write ("<script language=javascript>")
    Response.Write("function window_onload(){")
    Response.Write(sBlock)
    Response.Write("}</script>")
    }
    </SCRIPT>

    Pretty simple, right? Basically writing the client-side script block for
    the window_onload event, and all that contains is a string which was previously
    computed, which holds a javascript expression.

    The problem is entirely on the server side -- here's what you probably won't
    believe: despite the fact that they are in strings, the <script> and </script>
    text within the Response.Write's are being interpreted, both by the ASP editor,
    and by IIS, as functional tags ON THE SERVER. Of course I get an error because
    you can't have a script block inside a script block.

    I went further -- I changed my syntax coloring so that strings would be in
    bold purple. Indeed, the </script> within the string was NOT purple, but
    was colored as a functional script block.

    The workaround is this:

    <SCRIPT ID=serverEventHandlersJS LANGUAGE=javascript RUNAT=Server>

    function thisPage_onshow() {
    Response.Write ("<scrip" + "t language=javascript>")
    Response.Write("function window_onload(){")
    Response.Write(sBlock)
    // For some reason, you cannot put the script tags
    // in a string or comment without it getting interpreted
    // as the tag -- so it must be broken up.
    Response.Write("}</scrip" + "t>")
    }
    </SCRIPT>

    Basically, I cannot have "<script" nor "</script" together as content in
    any single string -- the script interpreter gets it wrong! So breaking it
    up like this works fine.

    Now, this is WAY to big a bug to believe. Basically, it is saying that the
    script interpretor and the ASP editor both can not tell correctly when a
    script has a string open or when it is in an HTML context. I just can't
    believe this. The ramifications for bugs are enormous.

    I then tried the same code, but in VB -- the problem actually is worse, both
    in VB and JavaScript: if you put </script or <script anywhere in a code comment,
    it too gets interpreted as an active tag, and the server throws up when it
    tries to run the page.

    As far as I can tell, once you enter a "script" tag, you'd better have nothing
    else within your code section that looks like a script open or closing tag.
    The code scanner must first scan for tags, and THEN look at the actual embedded
    code.

    Yet I find numerous examples in MSDN showing exactly this kind of script
    block creation in code, without the gyrations I'm going through, so what
    gives?

    Maybe it isn't the server interpretor? I have SOM, DTCs and the page object
    on these pages, so possibly SOM is causing it to mess up? Seems likely to
    me.

    But no mention of this can be found as a bug on MSDN site, and I find it
    difficult to believe I'm the first ever to find this.

    Can anybody reproduce this behavior?

    Thanks,

    Richard

  2. #2
    Betty Buhr Guest

    Re: Problem using "<script>" as a string in script!

    I believe this will work:

    Response.Write ("<scr" + "ipt language=javascript>")

    BettyB

    On 19 Jul 2001 11:54:37 -0700, "Richard Berman" <rb@sts1.com> wrote:

    >
    >OK, I'm bewildered. If what I'm seeing is true, then dozens of sample programs
    >wouldn't work. Let me tell you what I see.
    >
    >IIS 5, Win2K Server SP2, Visual Studio 6 SP5 (including InterDev). 750MHz,
    >512MB RAM, lots of disk space.
    >
    >I have a server-side script block (this was done both in VBScript and JavaScript).
    > I wanted it to look like so:
    >
    ><SCRIPT ID=serverEventHandlersJS LANGUAGE=javascript RUNAT=Server>
    >
    >function thisPage_onshow() {
    > Response.Write ("<script language=javascript>")
    > Response.Write("function window_onload(){")
    > Response.Write(sBlock)
    > Response.Write("}</script>")
    >}
    ></SCRIPT>
    >
    >Pretty simple, right? Basically writing the client-side script block for
    >the window_onload event, and all that contains is a string which was previously
    >computed, which holds a javascript expression.
    >
    >The problem is entirely on the server side -- here's what you probably won't
    >believe: despite the fact that they are in strings, the <script> and </script>
    >text within the Response.Write's are being interpreted, both by the ASP editor,
    >and by IIS, as functional tags ON THE SERVER. Of course I get an error because
    >you can't have a script block inside a script block.
    >
    >I went further -- I changed my syntax coloring so that strings would be in
    >bold purple. Indeed, the </script> within the string was NOT purple, but
    >was colored as a functional script block.
    >
    >The workaround is this:
    >
    ><SCRIPT ID=serverEventHandlersJS LANGUAGE=javascript RUNAT=Server>
    >
    >function thisPage_onshow() {
    > Response.Write ("<scrip" + "t language=javascript>")
    > Response.Write("function window_onload(){")
    > Response.Write(sBlock)
    > // For some reason, you cannot put the script tags
    > // in a string or comment without it getting interpreted
    > // as the tag -- so it must be broken up.
    > Response.Write("}</scrip" + "t>")
    >}
    ></SCRIPT>
    >
    >Basically, I cannot have "<script" nor "</script" together as content in
    >any single string -- the script interpreter gets it wrong! So breaking it
    >up like this works fine.
    >
    >Now, this is WAY to big a bug to believe. Basically, it is saying that the
    >script interpretor and the ASP editor both can not tell correctly when a
    >script has a string open or when it is in an HTML context. I just can't
    >believe this. The ramifications for bugs are enormous.
    >
    >I then tried the same code, but in VB -- the problem actually is worse, both
    >in VB and JavaScript: if you put </script or <script anywhere in a code comment,
    >it too gets interpreted as an active tag, and the server throws up when it
    >tries to run the page.
    >
    >As far as I can tell, once you enter a "script" tag, you'd better have nothing
    >else within your code section that looks like a script open or closing tag.
    > The code scanner must first scan for tags, and THEN look at the actual embedded
    >code.
    >
    >Yet I find numerous examples in MSDN showing exactly this kind of script
    >block creation in code, without the gyrations I'm going through, so what
    >gives?
    >
    >Maybe it isn't the server interpretor? I have SOM, DTCs and the page object
    >on these pages, so possibly SOM is causing it to mess up? Seems likely to
    >me.
    >
    >But no mention of this can be found as a bug on MSDN site, and I find it
    >difficult to believe I'm the first ever to find this.
    >
    >Can anybody reproduce this behavior?
    >
    >Thanks,
    >
    >Richard



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center