Quellcode durchsuchen

2008-11-21 Marek Habersack <[email protected]>

	* TemplateControlCompiler.cs: make the Bind regex stricter.
	When creating Eval expression from Bind, replace single quotes
	with double quotes. Fixes bug #447597
	When processing Bind expressions and the regex doesn't match,
	throw an exception.

2008-11-21  Marek Habersack  <[email protected]>

	* ControlBuilder.cs: in BindingContainerType if builder is a
	RootBuilder and no naming container is found, return typeof
	(Page). In the TemplateBuilder case return cb.ControlType, not
	this.ControlType.

svn path=/trunk/mcs/; revision=119661
Marek Habersack vor 17 Jahren
Ursprung
Commit
a2bad5bd17

+ 7 - 0
mcs/class/System.Web/System.Web.Compilation/ChangeLog

@@ -1,3 +1,10 @@
+2008-11-21  Marek Habersack  <[email protected]>
+
+	* TemplateControlCompiler.cs: make the Bind regex stricter.
+	When creating Eval expression from Bind, replace single quotes
+	with double quotes. Fixes bug #447597
+	When processing Bind expressions and the regex doesn't match,
+	throw an exception.
 
 2008-11-17 Gonzalo Paniagua Javier <[email protected]>
 

+ 28 - 5
mcs/class/System.Web/System.Web.Compilation/TemplateControlCompiler.cs

@@ -67,9 +67,9 @@ namespace System.Web.Compilation
 		
 #if NET_2_0
 		static Regex bindRegex = new Regex (@"Bind\s*\(\s*[""']+(.*?)[""']+((\s*,\s*[""']+(.*?)[""']+)?)\s*\)\s*%>", RegexOptions.Compiled | RegexOptions.IgnoreCase);
-		static Regex bindRegexInValue = new Regex (@"Bind\s*\(\s*[""']+(.*?)[""']+((\s*,\s*[""']+(.*?)[""']+)?)\s*\).*", RegexOptions.Compiled | RegexOptions.IgnoreCase);
+		static Regex bindRegexInValue = new Regex (@"Bind\s*\(\s*[""']+(.*?)[""']+((\s*,\s*[""']+(.*?)[""']+)?)\s*\)\s*$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
 #endif
-		static Regex evalRegexInValue = new Regex (@"Eval\s*\(\s*[""']+(.*?)[""']+((\s*,\s*[""']+(.*?)[""']+)?)\s*\).*", RegexOptions.Compiled | RegexOptions.IgnoreCase);
+		static Regex evalRegexInValue = new Regex (@"(.*)Eval\s*\(\s*[""']+(.*?)[""']+((\s*,\s*[""']+(.*?)[""']+)?)\s*\)(.*)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
 		
 		public TemplateControlCompiler (TemplateControlParser parser)
 			: base (parser)
@@ -467,15 +467,38 @@ namespace System.Web.Compilation
 		CodeExpression CreateEvalInvokeExpression (Regex regex, string value, bool isBind)
 		{
 			Match match = regex.Match (value);
-			if (!match.Success)
+			if (!match.Success) {
+#if NET_2_0
+				if (isBind)
+					throw new HttpParseException ("Bind invocation wasn't formatted properly.");
+#endif
 				return null;
+			}
 			
+			string sanitizedSnippet;
 			if (isBind)
-				return new CodeSnippetExpression ("Eval" + value.Substring (4));
+				sanitizedSnippet = SanitizeBindCall (match);
+			else
+				sanitizedSnippet = value;
 			
-			return new CodeSnippetExpression (value);
+			return new CodeSnippetExpression (sanitizedSnippet);
 		}
 
+		string SanitizeBindCall (Match match)
+		{
+			GroupCollection groups = match.Groups;
+			StringBuilder sb = new StringBuilder ("Eval(\"" + groups [1] + "\"");
+			Group second = groups [2];
+			if (second != null) {
+				string v = second.Value;
+				if (v != null && v.Length > 0)
+					sb.Append (",\"" + second + "\"");
+			}
+			
+			sb.Append (")");
+			return sb.ToString ();
+		}
+		
 		string DataBoundProperty (ControlBuilder builder, Type type, string varName, string value)
 		{
 			value = TrimDB (value, true);

+ 6 - 0
mcs/class/System.Web/System.Web.UI/ChangeLog

@@ -1,3 +1,9 @@
+2008-11-21  Marek Habersack  <[email protected]>
+
+	* ControlBuilder.cs: in BindingContainerType if builder is a
+	RootBuilder and no naming container is found, return typeof
+	(Page). In the TemplateBuilder case return cb.ControlType, not
+	this.ControlType.
 
 2008-11-18 Gonzalo Paniagua Javier <[email protected]>
 

+ 6 - 3
mcs/class/System.Web/System.Web.UI/ControlBuilder.cs

@@ -188,8 +188,11 @@ namespace System.Web.UI {
 		Type BindingContainerType {
 			get {
 				ControlBuilder cb = (this is TemplateBuilder && !(this is RootBuilder)) ? this : MyNamingContainer;
-				if (cb == null)
+				if (cb == null) {
+					if (this is RootBuilder)
+						return typeof (Page);
 					return typeof (Control);
+				}
 
 #if NET_2_0
 				if (cb != this && cb is ContentBuilderInternal && !typeof (INonBindingContainer).IsAssignableFrom (cb.BindingContainerType))
@@ -205,7 +208,7 @@ namespace System.Web.UI {
 					if (ct != null)
 						return ct;
 
-					ct = ControlType;
+					ct = cb.ControlType;
 					if (typeof (INonBindingContainer).IsAssignableFrom (ct) || !typeof (INamingContainer).IsAssignableFrom (ct))
 						return MyNamingContainer.BindingContainerType;
 					
@@ -215,7 +218,7 @@ namespace System.Web.UI {
 				ct = cb.ControlType;
 				if (typeof (INonBindingContainer).IsAssignableFrom (ct) || !typeof (INamingContainer).IsAssignableFrom (ct))
 					return MyNamingContainer.BindingContainerType;
-
+				
 				return cb.ControlType;
 			}
 		}