Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/mcs/class
diff options
context:
space:
mode:
authorAtsushi Eno <atsushieno@gmail.com>2004-06-14 07:08:53 +0400
committerAtsushi Eno <atsushieno@gmail.com>2004-06-14 07:08:53 +0400
commit75e131ed39fffe6639e307809e768cdef2b0a643 (patch)
tree5e636052f915b1670c60d2c233de06f20a038361 /mcs/class
parentfd1f7cc1c48fe0f19f22dd98e90087fd1af96dea (diff)
2004-06-14 Atsushi Enomoto <atsushi@ximian.com>
* HtmlEmitter.cs : Correct URL escape implementation. svn path=/trunk/mcs/; revision=29470
Diffstat (limited to 'mcs/class')
-rw-r--r--mcs/class/System.XML/Mono.Xml.Xsl/ChangeLog4
-rw-r--r--mcs/class/System.XML/Mono.Xml.Xsl/HtmlEmitter.cs86
2 files changed, 90 insertions, 0 deletions
diff --git a/mcs/class/System.XML/Mono.Xml.Xsl/ChangeLog b/mcs/class/System.XML/Mono.Xml.Xsl/ChangeLog
index 940694b6d99..2c381e63034 100644
--- a/mcs/class/System.XML/Mono.Xml.Xsl/ChangeLog
+++ b/mcs/class/System.XML/Mono.Xml.Xsl/ChangeLog
@@ -1,3 +1,7 @@
+2004-06-14 Atsushi Enomoto <atsushi@ximian.com>
+
+ * HtmlEmitter.cs : Correct URL escape implementation.
+
2004-06-06 Atsushi Enomoto <atsushi@ximian.com>
* XslTransformProcessor.cs : On document() function, close the
diff --git a/mcs/class/System.XML/Mono.Xml.Xsl/HtmlEmitter.cs b/mcs/class/System.XML/Mono.Xml.Xsl/HtmlEmitter.cs
index bf745c13e88..079d2aeae7e 100644
--- a/mcs/class/System.XML/Mono.Xml.Xsl/HtmlEmitter.cs
+++ b/mcs/class/System.XML/Mono.Xml.Xsl/HtmlEmitter.cs
@@ -13,6 +13,7 @@
using System;
using System.Collections;
+using System.Globalization;
using System.IO;
using System.Text;
using System.Xml;
@@ -282,11 +283,96 @@ namespace Mono.Xml.Xsl
writer.Write ("=\"");
openAttribute = true;
+
+ // URI attribute should be escaped.
+ string element = ((string) elementNameStack.Peek ()).ToLower (CultureInfo.InvariantCulture);
+ string attrName = null;
+ string [] attrNames = null;
+ switch (element) {
+ case "q":
+ case "blockquote":
+ case "ins":
+ case "del":
+ attrName = "cite";
+ break;
+ case "form":
+ attrName = "action";
+ break;
+ case "a":
+ case "area":
+ case "link":
+ case "base":
+ attrName = "href";
+ break;
+ case "head":
+ attrName = "profile";
+ break;
+ case "input":
+ attrNames = new string [] {"src", "usemap"};
+ break;
+ case "img":
+ attrNames = new string [] {"src", "usemap", "longdesc"};
+ break;
+ case "object":
+ attrNames = new string [] {"classid", "codebase", "data", "archive", "usemap"};
+ break;
+ case "script":
+ attrNames = new string [] {"src", "for"};
+ break;
+ }
+ if (attrNames != null) {
+ string attr = localName.ToLower (CultureInfo.InvariantCulture);
+ foreach (string a in attrNames) {
+ if (a == attr) {
+ value = UriEx.EscapeUri (value);
+ break;
+ }
+ }
+ }
+ else if (attrName != null && attrName == localName.ToLower (CultureInfo.InvariantCulture))
+ value = UriEx.EscapeUri (value);
WriteFormattedString (value);
openAttribute = false;
writer.Write ('\"');
}
+ class UriEx : Uri
+ {
+ private UriEx () : base ("urn:foo") {}
+
+ public static string EscapeUri (string input)
+ {
+ StringBuilder sb = new StringBuilder ();
+ int start = 0;
+ for (int i = 0; i < input.Length; i++) {
+ char c = input [i];
+ if (c < 32 || c > 127)
+ continue;
+ bool preserve = false;
+ switch (c) {
+ case '&':
+ case '<':
+ case '>':
+ case '"':
+ case '\'':
+ preserve = true;
+ break;
+ default:
+ preserve = UriEx.IsExcludedCharacter (c);
+ break;
+ }
+ if (preserve) {
+ sb.Append (EscapeString (input.Substring (start, i - start)));
+ sb.Append (c);
+ start = i + 1;
+ }
+ }
+ if (start < input.Length)
+ sb.Append (EscapeString (input.Substring (start)));
+ return sb.ToString ();
+ }
+ }
+
public override void WriteComment (string text) {
if (openElement)
CloseStartElement ();