Author: igorz
Date: 2007-03-12 05:12:43 -0500 (Mon, 12 Mar 2007)
New Revision: 74107

Modified:
   trunk/mcs/class/System.Web/System.Web.UI/ChangeLog
   trunk/mcs/class/System.Web/System.Web.UI/HtmlTextWriter.cs
   trunk/mcs/class/System.Web/Test/System.Web.UI/HtmlTextWriterTest.cs
Log:
2007-03-12 Igor Zelmanovich <[EMAIL PROTECTED]>

        * HtmlTextWriter.cs: fixed:
        - Fixed writing background-image style attribute (different behavior in
        1.1 and 2.0).
        - Does not encode 'name' attribute.
        - Always encode style attributes (for 2.0 only).



Modified: trunk/mcs/class/System.Web/System.Web.UI/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI/ChangeLog  2007-03-12 09:48:19 UTC 
(rev 74106)
+++ trunk/mcs/class/System.Web/System.Web.UI/ChangeLog  2007-03-12 10:12:43 UTC 
(rev 74107)
@@ -1,3 +1,11 @@
+2007-03-12 Igor Zelmanovich <[EMAIL PROTECTED]>
+
+       * HtmlTextWriter.cs: fixed:
+       - Fixed writing background-image style attribute (different behavior in
+       1.1 and 2.0).
+       - Does not encode 'name' attribute.
+       - Always encode style attributes (for 2.0 only).
+
 2007-03-06  Adar Wesley <[EMAIL PROTECTED]>
 
        * Page.cs: initial implementation of support for Async=true.  Added 

Modified: trunk/mcs/class/System.Web/System.Web.UI/HtmlTextWriter.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI/HtmlTextWriter.cs  2007-03-12 
09:48:19 UTC (rev 74106)
+++ trunk/mcs/class/System.Web/System.Web.UI/HtmlTextWriter.cs  2007-03-12 
10:12:43 UTC (rev 74107)
@@ -84,7 +84,8 @@
                
                public virtual void AddAttribute (HtmlTextWriterAttribute key, 
string value)
                {
-                       AddAttribute (key, value, true);
+                       bool fEncode = key != HtmlTextWriterAttribute.Name;
+                       AddAttribute (key, value, fEncode);
                }
        
        
@@ -98,7 +99,8 @@
                
                public virtual void AddAttribute (string name, string value)
                {
-                       AddAttribute (name, value, true);
+                       bool fEncode = String.Compare ("name", name, true, 
CultureInfo.InvariantCulture) != 0;
+                       AddAttribute (name, value, fEncode);
                }
        
                protected virtual void AddAttribute (string name, string value, 
HtmlTextWriterAttribute key)
@@ -114,6 +116,9 @@
                {
                        NextStyleStack ();
                        styles [styles_pos].name = name;
+#if NET_2_0
+                       value = HttpUtility.HtmlAttributeEncode (value);
+#endif
                        styles [styles_pos].value = value;
                        styles [styles_pos].key = key;
                }
@@ -176,8 +181,14 @@
                                
                                for (int i = 0; i <= styles_pos; i ++) {
                                        AddedStyle a = styles [i];
-                                       if (OnStyleAttributeRender (a.name, 
a.value, a.key))
+                                       if (OnStyleAttributeRender (a.name, 
a.value, a.key)) {
+#if NET_2_0
+                                               if (a.key == 
HtmlTextWriterStyle.BackgroundImage) {
+                                                       a.value = String.Concat 
("url(", HttpUtility.UrlPathEncode (a.value), ")");
+                                               }
+#endif
                                                WriteStyleAttribute (a.name, 
a.value, false);
+                                       }
                                }
 
                                Write (style_attr.value);                       
        
@@ -490,16 +501,11 @@
                        
                public virtual void WriteStyleAttribute (string name, string 
value)
                {
-                       WriteStyleAttribute (name, value, true);
+                       WriteStyleAttribute (name, value, false);
                }
 
                public virtual void WriteStyleAttribute (string name, string 
value, bool fEncode)
                {
-#if NET_2_0
-                       if (name == "background-image") {
-                               value = String.Concat ("url(", value, ")");
-                       }
-#endif
                        Write (name);
                        Write (StyleEqualsChar);
                        Write (EncodeAttributeValue (value, fEncode));
@@ -586,7 +592,7 @@
        
                public virtual void WriteAttribute (string name, string value)
                {
-                       WriteAttribute (name, value, true);
+                       WriteAttribute (name, value, false);
                }
 
                public override void WriteLine (char value)

Modified: trunk/mcs/class/System.Web/Test/System.Web.UI/HtmlTextWriterTest.cs
===================================================================
--- trunk/mcs/class/System.Web/Test/System.Web.UI/HtmlTextWriterTest.cs 
2007-03-12 09:48:19 UTC (rev 74106)
+++ trunk/mcs/class/System.Web/Test/System.Web.UI/HtmlTextWriterTest.cs 
2007-03-12 10:12:43 UTC (rev 74107)
@@ -177,7 +177,6 @@
                }
 
                // Which attrs fall here
-               [Category ("NotWorking")]
                [Test]
                public void NoEscapeAttrName ()
                {
@@ -185,6 +184,75 @@
                        w.RenderBeginTag (HtwTag.Div);
                        w.RenderEndTag ();
                        Assert.AreEqual ("<div 
name=\"cookies&cream\">\n\n</div>", sw.ToString ());
+               }
+               
+               [Test]
+               public void NoEscapeAttrName2 () {
+                       w.AddAttribute ("name", "cookies&cream");
+                       w.RenderBeginTag (HtwTag.Div);
+                       w.RenderEndTag ();
+                       Assert.AreEqual ("<div 
name=\"cookies&cream\">\n\n</div>", sw.ToString ());
+               }
+               
+               [Test]
+               public void NoEscapeAttrName3 () {
+                       w.AddAttribute (HtwAttribute.Name, "cookies&cream", 
true);
+                       w.RenderBeginTag (HtwTag.Div);
+                       w.RenderEndTag ();
+                       Assert.AreEqual ("<div 
name=\"cookies&amp;cream\">\n\n</div>", sw.ToString ());
+               }
+               
+               [Test]
+               public void NoEscapeAttrName4 () {
+                       w.AddAttribute ("NaMe", "cookies&cream");
+                       w.RenderBeginTag (HtwTag.Div);
+                       w.RenderEndTag ();
+                       Assert.AreEqual ("<div 
NaMe=\"cookies&cream\">\n\n</div>", sw.ToString ());
+               }
+               
+               [Test]
+               public void EscapeAttribute1 () {
+                       sw = new StringWriter ();
+                       sw.NewLine = "\n"; // Keep sanity.
+                       Poker w1 = new Poker (sw);
+
+                       w1.AddAttribute ("attr", "cookies&cream");
+                       w1.RenderBeginTag (HtwTag.Div);
+                       w1.RenderEndTag ();
+
+                       Assert.AreEqual ("cookies&amp;cream", 
w1.AttrValue_At_AddAttribute, "AttrValue_At_AddAttribute");
+                       Assert.AreEqual ("cookies&amp;cream", 
w1.AttrValue_At_OnAttributeRender, "AttrValue_At_OnAttributeRender");
+                       Assert.AreEqual ("<div 
attr=\"cookies&amp;cream\">\n\n</div>", sw.ToString ());
+               }
+               
+               [Test]
+               public void EscapeAttribute2 () {
+                       sw = new StringWriter ();
+                       sw.NewLine = "\n"; // Keep sanity.
+                       Poker w1 = new Poker (sw);
+
+                       w1.AddAttribute ("attr", "cookies&cream", false);
+                       w1.RenderBeginTag (HtwTag.Div);
+                       w1.RenderEndTag ();
+                       
+                       Assert.AreEqual ("cookies&cream", 
w1.AttrValue_At_AddAttribute, "AttrValue_At_AddAttribute");
+                       Assert.AreEqual ("cookies&cream", 
w1.AttrValue_At_OnAttributeRender, "AttrValue_At_OnAttributeRender");
+                       Assert.AreEqual ("<div 
attr=\"cookies&cream\">\n\n</div>", sw.ToString ());
+               }
+               
+               [Test]
+               public void EscapeAttribute3 () {
+                       sw = new StringWriter ();
+                       sw.NewLine = "\n"; // Keep sanity.
+                       Poker w1 = new Poker (sw);
+
+                       w1.AddAttribute ("attr", "cookies&cream", true);
+                       w1.RenderBeginTag (HtwTag.Div);
+                       w1.RenderEndTag ();
+                       
+                       Assert.AreEqual ("cookies&amp;cream", 
w1.AttrValue_At_AddAttribute, "AttrValue_At_AddAttribute");
+                       Assert.AreEqual ("cookies&amp;cream", 
w1.AttrValue_At_OnAttributeRender, "AttrValue_At_OnAttributeRender");
+                       Assert.AreEqual ("<div 
attr=\"cookies&amp;cream\">\n\n</div>", sw.ToString ());
                }       
 
                [Test]
@@ -267,7 +335,6 @@
                }
 
                [Test]
-               [Category ("NotWorking")]
                public void TagByNameGetsCaseChanged ()
                {
                        w.RenderBeginTag ("InPuT");
@@ -308,7 +375,7 @@
                }
 
                [Test]
-               public void AddStyleAttribute ()
+               public void AddStyleAttribute1 ()
                {
                        w.AddStyleAttribute 
(HtmlTextWriterStyle.BackgroundImage, "http://www.go-mono.com/";);
                        w.RenderBeginTag ("div");
@@ -321,26 +388,131 @@
                        Assert.AreEqual ("<div 
style=\"background-image:http://www.go-mono.com/;\";>\n\n</div>", sw.ToString 
());
 #endif
                }
+
+               [Test]
+               public void AddStyleAttribute3 ()
+               {
+                       sw = new StringWriter ();
+                       sw.NewLine = "\n"; // Keep sanity.
+                       Poker w1 = new Poker (sw);
+
+                       w1.AddStyleAttribute ("mystyle", "my value&space");
+                       w1.RenderBeginTag ("div");
+                       w1.RenderEndTag ();
+#if NET_2_0
+                       Assert.AreEqual ("my value&space", 
w1.StyleValue_At_AddStyleAttribute, "StyleValue_At_AddStyleAttribute");
+                       Assert.AreEqual ("my value&amp;space", 
w1.StyleValue_At_OnStyleAttributeRender, 
"StyleValue_At_OnStyleAttributeRender");
+                       Assert.AreEqual ("<div style=\"mystyle:my 
value&amp;space;\">\n\n</div>", sw.ToString ());
+#else
+                       Assert.AreEqual ("<div style=\"mystyle:my 
value&space;\">\n\n</div>", sw.ToString ());
+#endif
+               }
+
+               [Test]
+               public void WriteAttribute1 ()
+               {
+                       w.WriteAttribute ("attr", "my value&space");
+                       Assert.AreEqual (" attr=\"my value&space\"", 
sw.ToString ());
+               }
+
+               [Test]
+               public void WriteAttribute2 ()
+               {
+                       w.WriteAttribute ("attr", "my value&space", false);
+                       Assert.AreEqual (" attr=\"my value&space\"", 
sw.ToString ());
+               }
+
+               [Test]
+               public void WriteAttribute3 ()
+               {
+                       w.WriteAttribute ("attr", "my value&space", true);
+                       Assert.AreEqual (" attr=\"my value&amp;space\"", 
sw.ToString ());
+               }
+
+               [Test]
+               public void WriteStyleAttribute1 ()
+               {
+                       w.WriteStyleAttribute ("mystyle", "my value&space");
+                       Assert.AreEqual ("mystyle:my value&space;", sw.ToString 
());
+               }
+
+               [Test]
+               public void WriteStyleAttribute2 ()
+               {
+                       w.WriteStyleAttribute ("mystyle", "my value&space", 
false);
+                       Assert.AreEqual ("mystyle:my value&space;", sw.ToString 
());
+               }
+
+               [Test]
+               public void WriteStyleAttribute3 ()
+               {
+                       w.WriteStyleAttribute ("mystyle", "my value&space", 
true);
+                       Assert.AreEqual ("mystyle:my value&amp;space;", 
sw.ToString ());
+               }
                
 #if NET_2_0
                [Test]
-               [Category ("NotWorking")]
-               public void WriteStyleAttribute_BackgroundImage () 
+               public void WriteStyleAttribute_BackgroundImage1 () 
                {
                        w.WriteStyleAttribute ("background-image", 
"http://www.mainsoft.com/space here?a=b&c=d");
                        Assert.AreEqual 
("background-image:http://www.mainsoft.com/space here?a=b&c=d;", sw.ToString 
());
                }
                
                [Test]
-               [Category ("NotWorking")]
-               public void AddStyleAttribute_BackgroundImage () 
+               public void WriteStyleAttribute_BackgroundImage2 ()
                {
-                       w.AddStyleAttribute 
(HtmlTextWriterStyle.BackgroundImage, "http://www.mainsoft.com/space 
here?a=b&c=d");
-                       w.RenderBeginTag ("div");
-                       w.RenderEndTag ();
+                       w.WriteStyleAttribute ("BackGround-Image", 
"http://www.mainsoft.com/space here?a=b&c=d");
+                       Assert.AreEqual 
("BackGround-Image:http://www.mainsoft.com/space here?a=b&c=d;", sw.ToString 
());
+               }
+               
+               [Test]
+               public void AddStyleAttribute_BackgroundImage1 () 
+               {
+                       sw = new StringWriter ();
+                       sw.NewLine = "\n"; // Keep sanity.
+                       Poker w1 = new Poker (sw);
 
+                       w1.AddStyleAttribute 
(HtmlTextWriterStyle.BackgroundImage, "http://www.mainsoft.com/space 
here?a=b&c=d");
+                       w1.RenderBeginTag ("div");
+                       w1.RenderEndTag ();
+
+                       Assert.AreEqual ("http://www.mainsoft.com/space 
here?a=b&c=d", w1.StyleValue_At_AddStyleAttribute, 
"StyleValue_At_AddStyleAttribute");
+                       Assert.AreEqual ("http://www.mainsoft.com/space 
here?a=b&amp;c=d", w1.StyleValue_At_OnStyleAttributeRender, 
"StyleValue_At_OnStyleAttributeRender");
                        Assert.AreEqual ("<div 
style=\"background-image:url(http://www.mainsoft.com/space%20here?a=b&amp;c=d);\">\n\n</div>",
 sw.ToString ());
                }
+
+               [Test]
+               public void AddStyleAttribute_BackgroundImage2 ()
+               {
+                       sw = new StringWriter ();
+                       sw.NewLine = "\n"; // Keep sanity.
+                       Poker w1 = new Poker (sw);
+
+                       w1.AddStyleAttribute ("background-image", 
"http://www.mainsoft.com/space here?a=b&c=d");
+                       w1.RenderBeginTag ("div");
+                       w1.RenderEndTag ();
+
+                       Assert.AreEqual ("http://www.mainsoft.com/space 
here?a=b&c=d", w1.StyleValue_At_AddStyleAttribute, 
"StyleValue_At_AddStyleAttribute");
+                       Assert.AreEqual ("http://www.mainsoft.com/space 
here?a=b&amp;c=d", w1.StyleValue_At_OnStyleAttributeRender, 
"StyleValue_At_OnStyleAttributeRender");
+                       Assert.AreEqual ("<div 
style=\"background-image:url(http://www.mainsoft.com/space%20here?a=b&amp;c=d);\">\n\n</div>",
 sw.ToString ());
+               }
+
+               [Test]
+               public void AddStyleAttribute_BackgroundImage3 ()
+               {
+                       sw = new StringWriter ();
+                       sw.NewLine = "\n"; // Keep sanity.
+                       Poker w1 = new Poker (sw);
+                       
+                       w1.AddStyleAttribute ("BackGround-Image", 
"http://www.mainsoft.com/space here?a=b&c=d");
+                       w1.RenderBeginTag ("div");
+                       w1.RenderEndTag ();
+
+                       Assert.AreEqual ("http://www.mainsoft.com/space 
here?a=b&c=d", w1.StyleValue_At_AddStyleAttribute, 
"StyleValue_At_AddStyleAttribute");
+                       Assert.AreEqual ("http://www.mainsoft.com/space 
here?a=b&amp;c=d", w1.StyleValue_At_OnStyleAttributeRender, 
"StyleValue_At_OnStyleAttributeRender");
+                       Assert.AreEqual ("<div 
style=\"BackGround-Image:url(http://www.mainsoft.com/space%20here?a=b&amp;c=d);\">\n\n</div>",
 sw.ToString ());
+               }
+
 #endif
 
                [Test]
@@ -408,6 +580,44 @@
                        }
        
                }
+
+               class Poker : HtmlTextWriter
+               {
+                       public string StyleValue_At_OnStyleAttributeRender;
+                       public string StyleValue_At_AddStyleAttribute;
+                       public string AttrValue_At_OnAttributeRender;
+                       public string AttrValue_At_AddAttribute;
+
+                       public Poker (TextWriter tw)
+                               : base (tw)
+                       {
+                       }
+
+                       protected override bool OnAttributeRender (string name, 
string value, HtmlTextWriterAttribute key)
+                       {
+                               AttrValue_At_OnAttributeRender = value;
+                               return base.OnAttributeRender (name, value, 
key);
+                       }
+                       
+                       protected override bool OnStyleAttributeRender (string 
name, string value, HtmlTextWriterStyle key)
+                       {
+                               StyleValue_At_OnStyleAttributeRender = value;
+                               return base.OnStyleAttributeRender (name, 
value, key);
+                       }
+                       
+                       protected override void AddStyleAttribute (string name, 
string value, HtmlTextWriterStyle key)
+                       {
+                               StyleValue_At_AddStyleAttribute = value;
+                               base.AddStyleAttribute (name, value, key);
+                       }
+
+                       protected override void AddAttribute (string name, 
string value, HtmlTextWriterAttribute key)
+                       {
+                               AttrValue_At_AddAttribute = value;
+                               base.AddAttribute (name, value, key);
+                       }
+
+               }
                
                [Test]
                public void TestOnAttributeRender() {

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to