Sfoglia il codice sorgente

2010-07-09 Marek Habersack <[email protected]>

	* HtmlInputButton.cs: if ServerClick handler is found, do NOT
	attribute-encode the onclick attribute.

svn path=/trunk/mcs/; revision=160185
Marek Habersack 15 anni fa
parent
commit
b5de6386ee

+ 5 - 0
mcs/class/System.Web/System.Web.UI.HtmlControls/ChangeLog

@@ -1,3 +1,8 @@
+2010-07-09  Marek Habersack  <[email protected]>
+
+	* HtmlInputButton.cs: if ServerClick handler is found, do NOT
+	attribute-encode the onclick attribute.
+
 2010-06-21  Marek Habersack  <[email protected]>
 
 	* HtmlControl.cs: PreProcessRelativeReference deos not

+ 5 - 1
mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlInputButton.cs

@@ -233,7 +233,11 @@ namespace System.Web.UI.HtmlControls {
 				}
 
 				if (onclick.Length > 0) {
-					writer.WriteAttribute ("onclick", onclick, true);
+					bool encode = true;
+					if (Events [ServerClickEvent] != null)
+						encode = false; // tests show that this is indeed
+								// the case...
+					writer.WriteAttribute ("onclick", onclick, encode);
 					writer.WriteAttribute ("language", "javascript");
 				}
 			}

+ 11 - 3
mcs/class/System.Web/Test/System.Web.UI.HtmlControls/HtmlInputButtonTest.cs

@@ -169,6 +169,14 @@ namespace MonoTests.System.Web.UI.HtmlControls {
 		[Test]
 		public void OnClickAttributeWithSpecials ()
 		{
+#if NET_4_0
+			string origHtml = "alert(&#39;&lt;&amp;&#39;);";
+			string origHtml2 = "alert('<&');";
+#else
+			string origHtml = "alert('&lt;&amp;');";
+			string origHtml2 = "alert('<&');";
+#endif
+
 			StringWriter sw = new StringWriter ();
 			HtmlTextWriter tw = new HtmlTextWriter (sw);
 
@@ -177,14 +185,14 @@ namespace MonoTests.System.Web.UI.HtmlControls {
 			p.Attributes["onclick"] = "alert('<&');";
 			p.DoRenderAttributes (tw);
 			string str = sw.ToString ();
-			int found = str.IndexOf ("alert('&lt;&amp;');");
+			int found = str.IndexOf (origHtml);
 			Assert.IsTrue (found >= 0, "#01");
 			p.ServerClick += new EventHandler (EmptyHandler);
 			sw = new StringWriter ();
 			tw = new HtmlTextWriter (sw);
 			p.DoRenderAttributes (tw);
 			str = sw.ToString ();
-			found = str.IndexOf ("alert('&lt;&amp;');");
+			found = str.IndexOf (origHtml2);
 			Assert.IsTrue (found >= 0, "#02" + str);
 		}
 
@@ -228,7 +236,7 @@ namespace MonoTests.System.Web.UI.HtmlControls {
 		}
 
 		[Test]
-                [Category ("NotWorking")]
+		[Category ("NotWorking")]
 		public void RenderOnclick4 ()
 		{
 			Page page = new Page ();