[Mono-bugs] [Bug 52522][Wis] New - <% tags should not be processed inside client side <script> block

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Sun, 1 Feb 2004 19:27:27 -0500 (EST)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by liyul@hotmail.com.

http://bugzilla.ximian.com/show_bug.cgi?id=52522

--- shadow/52522	2004-02-01 19:27:27.000000000 -0500
+++ shadow/52522.tmp.13273	2004-02-01 19:27:27.000000000 -0500
@@ -0,0 +1,188 @@
+Bug#: 52522
+Product: Mono/Class Libraries
+Version: unspecified
+OS: unknown
+OS Details: 
+Status: ASSIGNED   
+Resolution: 
+Severity: Unknown
+Priority: Wishlist
+Component: Sys.Web
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: liyul@hotmail.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: <% tags should not be processed inside client side <script> block
+
+If there are <%=var%> in javascript block, they will be left there not
+processed. It is a rather major issue with aspx compatibility.
+
+bug: In AspGenerator.cs, the TextParsed method deliberately skip processing
+  <% in server-side or client scripts.
+
+		void TextParsed (ILocation location, string text)
+		{
+			if (text.IndexOf ("<%") != -1 && !inScript && !javascript) {
+				if (this.text.Length > 0)
+					FlushText ();
+				CodeRenderParser r = new CodeRenderParser (text, stack.Builder);
+				r.AddChildren ();
+				return;
+			}
+
+			this.text.Append (text);
+			//PrintLocation (location);
+		}
+
+Temporary fix enclosed seemed to be working, but need further scrutinzation.
+
+		void TextParsed (ILocation location, string text)
+		{
+			//PrintLocation (location);
+			PrintLocation(location);
+
+			if (text.IndexOf ("<%") != -1) 
+			{
+				if (inScript) 
+				{
+					// FIXME:
+					this.text.Append (text);
+				}
+				else if (javascript) 
+				{
+					// FIXME:
+					// this.text.Append (text);
+					if (this.text.Length > 0)
+						FlushText ();
+					CodeRenderParser r = new CodeRenderParser (text, stack.Builder);
+					r.AddChildren ();
+					return;
+				} 
+				else
+				{
+					if (this.text.Length > 0)
+						FlushText ();
+					CodeRenderParser r = new CodeRenderParser (text, stack.Builder);
+					r.AddChildren ();
+					return;
+				} 
+			} 
+			else 
+			{
+				this.text.Append (text);
+			}
+		}
+
+------- Additional Comments From jackson@ximian.com  2003-12-25 06:03 -------
+This is fixed in CVS, thanks for the report.
+
+------- Additional Comments From liyul@hotmail.com  2004-02-01 19:27 -------
+It was not fixed properly as of snapshot 1/15/04. I am including this
+test .aspx file to demonstrate the bug. When processing "result < zero
+", the parser would treat it as tag rather than text.
+
+<%@ Page Language="c#" %>
+<script runat="server">
+
+    void SubmitBtn_Click(Object sender, EventArgs e) {
+      Response.Write("Hi");
+    }
+
+</script>
+<html>
+<head>
+    <title>Test</title>
+<script language="JavaScript">
+
+function blah2 () {
+    var result;
+    var zero;
+    zero = 0;
+    <% Response.Write("result=10;\r\n"); %>
+
+    <% for ( int i=0; i < 10; i++ ) { %>
+        result += <%= (i < 5? 9-i : i) %>;
+    <% } %>
+
+    if (result < zero)
+        return result;
+    if (result<=0)
+        return result;
+    if (result==0)
+        return result;
+    if (result>=0)
+        return result;
+    if (result>0)
+        return result;
+
+}
+
+</script>
+</head>
+<body onload="javascript: alert(blah2())" >
+    <%Response.Write("Test");%><% for ( int i=0; i<10; i++ ) { %><font
+size="<%= i %>">Hello
+    World!<br />
+    </font><% } %>
+    <form action="test.aspx" method="post" runat="server">
+        <asp:button id="Button1" onclick="SubmitBtn_Click"
+runat="server" text="Click Me"></asp:button>
+    </form>
+</body>
+</html>
+
+These fixes are needed for snapshot as of 1/15/04:
+
+1. In class AspTokenizer, added a StringBuilder member "odds" to
+collect characters before identifier_start_character so that we can
+get them back in case later need.
+
+32c32
+< 		StringBuilder sb, odds;
+
+---
+> 		StringBuilder sb;
+46d45
+< 			odds= new StringBuilder();
+
+156d154
+< 			odds.Length=0;
+
+224,225d221
+< 				// keep otherwise discarded characters in case we need.
+
+< 				odds.Append((char) c);
+
+242,247d237
+< 		public string Odds {
+
+< 			get {
+
+< 				return odds.ToString();
+
+< 			}
+
+< 		}
+
+< 
+
+
+2. In AspParser.cs, for function "void GetTag (out TagType tagtype,
+out string id, out TagAttributes attributes)", fix it under "case
+Token.IDENTIFIER:"
+
+246,251d245
+< 				if (this.filename == "@@inner_string@@") {
+< 					// Actually not tag but "xxx < yyy" stuff in inner_string!
+< 					tagtype = TagType.Text;
+< 					tokenizer.InTag = false;
+< 					id = "<" + tokenizer.Odds + tokenizer.Value;
+< 				} else {
+265d258
+< 				}
+
+notes: JavaScript wouldn't mind whether spaces were preserved after
+'<' operator or not. But preserve such text verbatimly will help other
+languages later.