</script> in String Constant

Discussion in 'ASP .Net' started by Jonathan Wood, Dec 16, 2007.

  1. I have an ASPX page with my C# code in a <script> block within the page
    itself (not a code-behind file).

    Within that code, the syntax highlighter indicates the following string
    constant ends just before the "</script>", and the line produces the error
    "Newline in constant." Changing that portion of the string to "<//script>"
    causes the syntax highlighter to indicate a normal string.

    string jScript = "<script>document.forms[0].submit();</script>";

    Okay, so I would expect </script> to end my ASP.NET script block, but not
    when it appears within a string constant.

    Is this a bug, or am I prohibitted from having string constants that contain
    "</script>"?

    Thanks.

    --
    Jonathan Wood
    SoftCircuits Programming
    http://www.softcircuits.com
     
    Jonathan Wood, Dec 16, 2007
    #1
    1. Advertising

  2. Without any particular knowledge, I am just guessing.

    I guess it does make sense. How does the guy sitting behind your screen and
    compiling your scripts know where the script ends? He knows it by the
    </script> tag. How can he know that the tag is within some
    language-dependant element like a string? Probably he can't. Perhaps, he
    first defines where the script begins and ends and then passes the whole
    script for compiling. If it is true, he can't ignore the </script> tag
    inside a string simply because he doesn't know anything about c# strings at
    this stage.

    --
    Eliyahu Goldin,
    Software Developer
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin
    http://usableasp.net


    "Jonathan Wood" <> wrote in message
    news:...
    >I have an ASPX page with my C# code in a <script> block within the page
    >itself (not a code-behind file).
    >
    > Within that code, the syntax highlighter indicates the following string
    > constant ends just before the "</script>", and the line produces the error
    > "Newline in constant." Changing that portion of the string to "<//script>"
    > causes the syntax highlighter to indicate a normal string.
    >
    > string jScript = "<script>document.forms[0].submit();</script>";
    >
    > Okay, so I would expect </script> to end my ASP.NET script block, but not
    > when it appears within a string constant.
    >
    > Is this a bug, or am I prohibitted from having string constants that
    > contain "</script>"?
    >
    > Thanks.
    >
    > --
    > Jonathan Wood
    > SoftCircuits Programming
    > http://www.softcircuits.com
    >
     
    Eliyahu Goldin, Dec 16, 2007
    #2
    1. Advertising

  3. Eliyahu,

    > Without any particular knowledge, I am just guessing.
    >
    > I guess it does make sense. How does the guy sitting behind your screen
    > and compiling your scripts know where the script ends? He knows it by the
    > </script> tag. How can he know that the tag is within some
    > language-dependant element like a string? Probably he can't. Perhaps, he
    > first defines where the script begins and ends and then passes the whole
    > script for compiling. If it is true, he can't ignore the </script> tag
    > inside a string simply because he doesn't know anything about c# strings
    > at this stage.


    Maybe, but it seems a bit limiting if you can put stuff like that even
    within a constant.

    --
    Jonathan Wood
    SoftCircuits Programming
    http://www.softcircuits.com


    >
    > --
    > Eliyahu Goldin,
    > Software Developer
    > Microsoft MVP [ASP.NET]
    > http://msmvps.com/blogs/egoldin
    > http://usableasp.net
    >
    >
    > "Jonathan Wood" <> wrote in message
    > news:...
    >>I have an ASPX page with my C# code in a <script> block within the page
    >>itself (not a code-behind file).
    >>
    >> Within that code, the syntax highlighter indicates the following string
    >> constant ends just before the "</script>", and the line produces the
    >> error "Newline in constant." Changing that portion of the string to
    >> "<//script>" causes the syntax highlighter to indicate a normal string.
    >>
    >> string jScript = "<script>document.forms[0].submit();</script>";
    >>
    >> Okay, so I would expect </script> to end my ASP.NET script block, but not
    >> when it appears within a string constant.
    >>
    >> Is this a bug, or am I prohibitted from having string constants that
    >> contain "</script>"?
    >>
    >> Thanks.
    >>
    >> --
    >> Jonathan Wood
    >> SoftCircuits Programming
    >> http://www.softcircuits.com
    >>

    >
    >
     
    Jonathan Wood, Dec 16, 2007
    #3
  4. "Eliyahu Goldin" <> wrote in
    message news:...


    > I guess it does make sense. How does the guy sitting behind your screen
    > and compiling your scripts know where the script ends? He knows it by the
    > </script> tag.


    unless that </script> tag is part of a string of characters enclosed within
    double quotes; in effect: ok, I'm looking for the end of the script block
    ... oh, some quotation marks here ... now let me look for the close quotation
    mark before I resume looking for the close of the script block ... no? what
    am I missing?

    > How can he know that the tag is within some language-dependant element
    > like a string? Probably he can't. Perhaps, he first defines where the
    > script begins and ends and then passes the whole script for compiling.


    > If it is true, he can't ignore the </script> tag inside a string simply
    > because he doesn't know anything about c# strings at this stage.


    why not? "he" is a C# compiler after all; I'm not understanding why "he"
    can't look at this:

    string jScript = "<script>document.forms[0].submit();</script>";

    and know that we have a string assignment going on and </script> is not
    ending anything in this context ... or that <script> is not violating any
    nesting rules
     
    Barrie Wilson, Dec 16, 2007
    #4
  5. The more I think about this, the more I think "he" is NOT a C# compiler.

    I suspect what is happending is the ASPX parser first pulls out script code
    and then passes that script to the C# compiler. So it is the ASPX parser
    that determines where the end of the script is, not the compiler.

    Definitely a quirk, but my best assessment is that this is what is
    happening.

    --
    Jonathan Wood
    SoftCircuits Programming
    http://www.softcircuits.com


    "Barrie Wilson" <> wrote in message
    news:...
    >
    > "Eliyahu Goldin" <> wrote in
    > message news:...
    >
    >
    >> I guess it does make sense. How does the guy sitting behind your screen
    >> and compiling your scripts know where the script ends? He knows it by the
    >> </script> tag.

    >
    > unless that </script> tag is part of a string of characters enclosed
    > within double quotes; in effect: ok, I'm looking for the end of the
    > script block .. oh, some quotation marks here ... now let me look for the
    > close quotation mark before I resume looking for the close of the script
    > block ... no? what am I missing?
    >
    >> How can he know that the tag is within some language-dependant element
    >> like a string? Probably he can't. Perhaps, he first defines where the
    >> script begins and ends and then passes the whole script for compiling.

    >
    >> If it is true, he can't ignore the </script> tag inside a string simply
    >> because he doesn't know anything about c# strings at this stage.

    >
    > why not? "he" is a C# compiler after all; I'm not understanding why "he"
    > can't look at this:
    >
    > string jScript = "<script>document.forms[0].submit();</script>";
    >
    > and know that we have a string assignment going on and </script> is not
    > ending anything in this context ... or that <script> is not violating any
    > nesting rules
    >
    >
    >
    >
     
    Jonathan Wood, Dec 16, 2007
    #5
  6. "Jonathan Wood" <> wrote in message
    news:%...
    > The more I think about this, the more I think "he" is NOT a C# compiler.
    >
    > I suspect what is happending is the ASPX parser first pulls out script
    > code and then passes that script to the C# compiler. So it is the ASPX
    > parser that determines where the end of the script is, not the compiler.
    >
    > Definitely a quirk, but my best assessment is that this is what is
    > happening.


    whatever ... the code you're writing should be parsable by *something*
    rather than erroring out is my point; I didn't think it was really the
    point which code was doing which work here ... or does someone disagree that
    it should be parsable without error ... the expression is not ambiguous the
    way I see it


    > --
    > Jonathan Wood
    > SoftCircuits Programming
    > http://www.softcircuits.com
    >
    >
    > "Barrie Wilson" <> wrote in message
    > news:...
    >>
    >> "Eliyahu Goldin" <> wrote in
    >> message news:...
    >>
    >>
    >>> I guess it does make sense. How does the guy sitting behind your screen
    >>> and compiling your scripts know where the script ends? He knows it by
    >>> the </script> tag.

    >>
    >> unless that </script> tag is part of a string of characters enclosed
    >> within double quotes; in effect: ok, I'm looking for the end of the
    >> script block .. oh, some quotation marks here ... now let me look for the
    >> close quotation mark before I resume looking for the close of the script
    >> block ... no? what am I missing?
    >>
    >>> How can he know that the tag is within some language-dependant element
    >>> like a string? Probably he can't. Perhaps, he first defines where the
    >>> script begins and ends and then passes the whole script for compiling.

    >>
    >>> If it is true, he can't ignore the </script> tag inside a string simply
    >>> because he doesn't know anything about c# strings at this stage.

    >>
    >> why not? "he" is a C# compiler after all; I'm not understanding why
    >> "he" can't look at this:
    >>
    >> string jScript = "<script>document.forms[0].submit();</script>";
    >>
    >> and know that we have a string assignment going on and </script> is not
    >> ending anything in this context ... or that <script> is not violating any
    >> nesting rules
    >>
    >>
    >>
    >>

    >
     
    Barrie Wilson, Dec 16, 2007
    #6
  7. Yes, this is what I wanted to say.

    --
    Eliyahu Goldin,
    Software Developer
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin
    http://usableasp.net


    "Jonathan Wood" <> wrote in message
    news:%...
    > The more I think about this, the more I think "he" is NOT a C# compiler.
    >
    > I suspect what is happending is the ASPX parser first pulls out script
    > code and then passes that script to the C# compiler. So it is the ASPX
    > parser that determines where the end of the script is, not the compiler.
    >
    > Definitely a quirk, but my best assessment is that this is what is
    > happening.
    >
    > --
    > Jonathan Wood
    > SoftCircuits Programming
    > http://www.softcircuits.com
    >
    >
    > "Barrie Wilson" <> wrote in message
    > news:...
    >>
    >> "Eliyahu Goldin" <> wrote in
    >> message news:...
    >>
    >>
    >>> I guess it does make sense. How does the guy sitting behind your screen
    >>> and compiling your scripts know where the script ends? He knows it by
    >>> the </script> tag.

    >>
    >> unless that </script> tag is part of a string of characters enclosed
    >> within double quotes; in effect: ok, I'm looking for the end of the
    >> script block .. oh, some quotation marks here ... now let me look for the
    >> close quotation mark before I resume looking for the close of the script
    >> block ... no? what am I missing?
    >>
    >>> How can he know that the tag is within some language-dependant element
    >>> like a string? Probably he can't. Perhaps, he first defines where the
    >>> script begins and ends and then passes the whole script for compiling.

    >>
    >>> If it is true, he can't ignore the </script> tag inside a string simply
    >>> because he doesn't know anything about c# strings at this stage.

    >>
    >> why not? "he" is a C# compiler after all; I'm not understanding why
    >> "he" can't look at this:
    >>
    >> string jScript = "<script>document.forms[0].submit();</script>";
    >>
    >> and know that we have a string assignment going on and </script> is not
    >> ending anything in this context ... or that <script> is not violating any
    >> nesting rules
    >>
    >>
    >>
    >>

    >
     
    Eliyahu Goldin, Dec 17, 2007
    #7
  8. Jonathan Wood

    Hans Kesting Guest

    Jonathan Wood pretended :
    > I have an ASPX page with my C# code in a <script> block within the page
    > itself (not a code-behind file).
    >
    > Within that code, the syntax highlighter indicates the following string
    > constant ends just before the "</script>", and the line produces the error
    > "Newline in constant." Changing that portion of the string to "<//script>"
    > causes the syntax highlighter to indicate a normal string.
    >
    > string jScript = "<script>document.forms[0].submit();</script>";
    >
    > Okay, so I would expect </script> to end my ASP.NET script block, but not
    > when it appears within a string constant.
    >
    > Is this a bug, or am I prohibitted from having string constants that contain
    > "</script>"?
    >
    > Thanks.


    In old ASP the usual workaround was
    string jScript = "<script>document.forms[0].submit();</sc" + "ript>";


    Hans Kesting
     
    Hans Kesting, Dec 17, 2007
    #8
    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. Christopher M. Lusardi
    Replies:
    1
    Views:
    4,096
  2. Martin Magnusson
    Replies:
    2
    Views:
    510
    John Harrison
    Oct 8, 2004
  3. Tor Erik Soenvisen
    Replies:
    14
    Views:
    565
    Tim Roberts
    Nov 23, 2006
  4. Replies:
    4
    Views:
    339
    Keith Thompson
    Dec 14, 2006
  5. sinbad
    Replies:
    7
    Views:
    661
    sinbad
    Jun 19, 2008
Loading...

Share This Page