Re: Escape Sequences
- From: "Liz" <liz@xxxxxxxxxxxxxxx>
- Date: Sun, 16 Dec 2007 17:54:44 -0600
"Jon Skeet [C# MVP]" <skeet@xxxxxxxxx> wrote in message
news:MPG.21cf9999a727a1a970c@xxxxxxxxxxxxxxxxxxxxxxx
Liz <liz@xxxxxxxxxxxxxxx> wrote:
Why would it be a compiler bug? The C# compiler has been passed this:
void Page_Load()
{
if (!Page.IsPostBack)
{
litYear.Text = DateTime.Now.Year.ToString();
string jScript = "<script>document.forms[0].submit();</script>
That piece of code has all the problems which are reported.
no, it was passed:
string jScript = "<script>document.forms[0].submit();</script>";
What makes you say that? That wouldn't explain the errors that were
produced, whereas my (corrected below) version does.
because that was the code the OP posted ... and it does produce the errors
originally reported when in it resides in an .ASPX file
I do have a correction, though: I believe it was actually passed:
void Page_Load()
{
if (!Page.IsPostBack)
{
litYear.Text = DateTime.Now.Year.ToString();
string jScript = "<script>document.forms[0].submit();
In other words, everything before the </script>.
I'm not clear what you mean, Jon ... that you "have a correction" ... what
you think the OP really meant to say? the code above has an unclosed quote
.... ??
why should that generate an error, anymore than:
void myMethod()
{
string s = "I put a } character in here;";
}
should generate an error?
That's *just* C# code - the only thing that has to work with it is the
C# compiler. Compare that with the ASP.NET situation: the ASP.NET
engine has to pick out bit of code within <script runat="server"> and
</script> tags, and pass those off to another compiler. It doesn't
understand the contents of the element.
right ... and doesn't really need to; the string assigned to the variable
jScript was intended to run on the client (although the implementation was
never fully spelled out in this thread)
So, without any direct knowledge of the language it's working with, how
should it find out which is a "real" </script> and which is one which
actually just happens to be part of the code?
again, it's not working with a language here; it's only working with a
string of characters comprising some Javascript code
This is always going to be a problem when embedding code from one
language within another - there has to be a way of detecting where the
embedded code ends. It looks like the ASP.NET engine just looks for the
first </script> after the opening tag, and passes everything between
the two to the appropriate language compiler.
which seems to make the ASP.NET engine a little dumber than it might be, no?
it should have ignored the first </script> it encountered because it was
between quotation marks
Compared with any other mechanism it would have to use to find the end
of the code block, I'm pretty comfortable with the decision that's been
made.
well, I don't know that I'm "uncomfortable" with any of this but I am
puzzled why it has any particular difficulty in simply recognizing a quoted
literal being assigned to a string var and ignoring it for purposes of
identifying the begin/end of the <script></script> block
.
- Follow-Ups:
- Re: Escape Sequences
- From: Jon Skeet [C# MVP]
- Re: Escape Sequences
- References:
- Escape Sequences
- From: Jonathan Wood
- Re: Escape Sequences
- From: Peter Duniho
- Re: Escape Sequences
- From: Jonathan Wood
- Re: Escape Sequences
- From: Liz
- Re: Escape Sequences
- From: Jon Skeet [C# MVP]
- Re: Escape Sequences
- From: Liz
- Re: Escape Sequences
- From: Jon Skeet [C# MVP]
- Escape Sequences
- Prev by Date: Re: make the computer press keys
- Next by Date: Re: Find a Program Path
- Previous by thread: Re: Escape Sequences
- Next by thread: Re: Escape Sequences
- Index(es):
Relevant Pages
|