diff options
author | Gonzalo Paniagua Javier <gonzalo.mono@gmail.com> | 2009-07-25 02:14:23 +0400 |
---|---|---|
committer | Gonzalo Paniagua Javier <gonzalo.mono@gmail.com> | 2009-07-25 02:14:23 +0400 |
commit | 797a65c2f51daf907f2ff8a6bc1c8a37aa9e3183 (patch) | |
tree | 0787214ef8b927559905fce7133da664cde3edb1 | |
parent | 7337b45f49fadaff8f310b5d432240128b82786d (diff) |
revert 138512, which comes from trunk 138474
svn path=/branches/mono-2-4-2/mcs/; revision=138657
-rw-r--r-- | mcs/class/System.Web/System.Web.Compilation/AspGenerator.cs | 212 | ||||
-rw-r--r-- | mcs/class/System.Web/System.Web.Compilation/ChangeLog | 10 |
2 files changed, 94 insertions, 128 deletions
diff --git a/mcs/class/System.Web/System.Web.Compilation/AspGenerator.cs b/mcs/class/System.Web/System.Web.Compilation/AspGenerator.cs index 9fd7e5e14eb..9a566676810 100644 --- a/mcs/class/System.Web/System.Web.Compilation/AspGenerator.cs +++ b/mcs/class/System.Web/System.Web.Compilation/AspGenerator.cs @@ -3,10 +3,9 @@ // // Authors: // Gonzalo Paniagua Javier (gonzalo@ximian.com) -// Marek Habersack <mhabersack@novell.com> // // (C) 2002,2003 Ximian, Inc (http://www.ximian.com) -// Copyright (c) 2004-2009 Novell, Inc (http://www.novell.com) +// Copyright (c) 2004,2006 Novell, Inc (http://www.novell.com) // // @@ -182,26 +181,6 @@ namespace System.Web.Compilation } } - enum TextBlockType - { - Verbatim, - Expression, - Tag, - Comment - } - - sealed class TextBlock - { - public string Content; - public readonly TextBlockType Type; - - public TextBlock (TextBlockType type, string content) - { - Content = content; - Type = type; - } - } - class AspGenerator { #if NET_2_0 @@ -209,26 +188,6 @@ namespace System.Web.Compilation internal static Regex DirectiveRegex = new Regex (@"<%\s*@(\s*(?<attrname>\w[\w:]*(?=\W))(\s*(?<equal>=)\s*""(?<attrval>[^""]*)""|\s*(?<equal>=)\s*'(?<attrval>[^']*)'|\s*(?<equal>=)\s*(?<attrval>[^\s%>]*)|(?<equal>)(?<attrval>\s*?)))*\s*?%>", RegexOptions.Compiled | RegexOptions.IgnoreCase); #endif - static readonly Regex runatServer = new Regex (@"<[\w:\.]+.*?runat=[""']?server[""']?.*?/?>", - RegexOptions.Compiled | RegexOptions.Singleline | - RegexOptions.Multiline | RegexOptions.IgnoreCase | - RegexOptions.CultureInvariant); - - static readonly Regex endOfTag = new Regex (@"</[\w:\.]+\s*>", - RegexOptions.Compiled | RegexOptions.Singleline | - RegexOptions.Multiline | RegexOptions.IgnoreCase | - RegexOptions.CultureInvariant); - - static readonly Regex expressionRegex = new Regex (@"<%.*%>", - RegexOptions.Compiled | RegexOptions.Singleline | - RegexOptions.Multiline | RegexOptions.IgnoreCase | - RegexOptions.CultureInvariant); - - static readonly Regex clientCommentRegex = new Regex (@"<!--.*-->", - RegexOptions.Compiled | RegexOptions.Singleline | - RegexOptions.Multiline | RegexOptions.IgnoreCase | - RegexOptions.CultureInvariant); - ParserStack pstack; BuilderLocationStack stack; TemplateParser tparser; @@ -798,6 +757,10 @@ namespace System.Web.Compilation // The kludge supports only self-closing tags inside attributes. // // KLUDGE WARNING!! + static readonly Regex runatServer=new Regex (@"<[\w:\.]+.*?runat=[""']?server[""']?.*?/>", + RegexOptions.Compiled | RegexOptions.Singleline | + RegexOptions.Multiline | RegexOptions.IgnoreCase | + RegexOptions.CultureInvariant); bool ProcessTagsInAttributes (ILocation location, string tagid, TagAttributes attributes, TagType type) { if (attributes == null || attributes.Count == 0) @@ -889,9 +852,9 @@ namespace System.Web.Compilation Directory.SetCurrentDirectory (origdir); if (newdir [newdir.Length - 1] != '/') newdir += "/"; - } catch (DirectoryNotFoundException ex) { + } catch (DirectoryNotFoundException) { return; // will be converted into 404 - } catch (FileNotFoundException ex) { + } catch (FileNotFoundException) { return; // as above } catch (Exception ex) { // better safe than sorry @@ -1043,105 +1006,118 @@ namespace System.Web.Compilation return Path.GetFullPath (Path.Combine (basedir, filename)); } - - delegate bool CheckBlockEnd (string text); - bool CheckTagEndNeeded (string text) + void TextParsed (ILocation location, string text) { - return !text.EndsWith ("/>"); - } - + if (ignore_text) + return; + + // Another gross hack - get rid of comments in the parsed text + int textLen = text.Length; + int textMaxIndex = textLen - 1; + int commentStart = text.IndexOf ("<!--"); + int commentLastStart = 0; #if NET_2_0 - List <TextBlock> + List <int> commentRanges = null; #else - ArrayList + ArrayList commentRanges = null; #endif - FindRegexBlocks (Regex rxStart, Regex rxEnd, CheckBlockEnd checkEnd, IList blocks, TextBlockType typeForMatches, bool discardBlocks) - { + + while (commentStart != -1) { + int commentEnd = text.IndexOf ("-->", commentStart); + + if (commentEnd == -1) { + if (commentStart == 0) + return; + commentEnd = textMaxIndex; + } + + if (commentRanges == null) { #if NET_2_0 - var ret = new List <TextBlock> (); + commentRanges = new List <int> (); #else - ArrayList ret = new ArrayList (); + commentRanges = new ArrayList (); #endif - - foreach (TextBlock block in blocks) { - if (block.Type != TextBlockType.Verbatim) { - ret.Add (block); - continue; } - int lastIndex = 0, index; - MatchCollection matches = rxStart.Matches (block.Content); - bool foundMatches = matches.Count > 0; - foreach (Match match in matches) { - foundMatches = true; - index = match.Index; - if (lastIndex < index) - ret.Add (new TextBlock (TextBlockType.Verbatim, block.Content.Substring (lastIndex, index - lastIndex))); + if (commentStart > commentLastStart) { + commentRanges.Add (commentLastStart); + commentRanges.Add (commentStart); + } - string value = match.Value; - if (rxEnd != null && checkEnd (value)) { - int startFrom = index + value.Length; - Match m = rxEnd.Match (block.Content, startFrom); - if (m.Success) - value += block.Content.Substring (startFrom, m.Index - startFrom) + m.Value; + if (commentEnd == textMaxIndex) + break; + + commentLastStart = commentEnd + 3; + if (commentLastStart > textMaxIndex) + break; + + commentStart = text.IndexOf ("<!--", commentLastStart); + if (commentStart == -1) { + int tailLength = textMaxIndex - commentLastStart; + if (tailLength > 0) { + commentRanges.Add (commentLastStart); + commentRanges.Add (tailLength); } - - if (!discardBlocks) - ret.Add (new TextBlock (typeForMatches, value)); - lastIndex = index + value.Length; + break; } - - if (lastIndex > 0 && lastIndex < block.Content.Length) - ret.Add (new TextBlock (TextBlockType.Verbatim, block.Content.Substring (lastIndex))); - - if (!foundMatches) - ret.Add (block); } - return ret; - } - - IList SplitTextIntoBlocks (string text) - { + if (commentRanges != null) { + if (commentRanges.Count == 0) + return; + + StringBuilder sb = new StringBuilder (); + for (int i = 0; i < commentRanges.Count; i += 2) { #if NET_2_0 - var ret = new List <TextBlock> (); + sb.Append (text.Substring (commentRanges [i], commentRanges [i + 1])); #else - ArrayList ret = new ArrayList (); + sb.Append (text.Substring ((int)commentRanges [i], (int)commentRanges [i + 1])); #endif + } - ret.Add (new TextBlock (TextBlockType.Verbatim, text)); - ret = FindRegexBlocks (clientCommentRegex, null, null, ret, TextBlockType.Comment, true); - ret = FindRegexBlocks (runatServer, endOfTag, CheckTagEndNeeded, ret, TextBlockType.Tag, false); - ret = FindRegexBlocks (expressionRegex, null, null, ret, TextBlockType.Expression, false); + string noComments = sb.ToString ().Trim (); + if (noComments.Length == 0) + return; - return ret; - } + text = noComments; + } - void TextParsed (ILocation location, string text) - { - if (ignore_text) + // And again... the first one wins - if we have expressions and server-side + // controls together in one block of plain text, tough luck... + if (text.IndexOf ("<%") != -1 && !inScript) { + if (this.text.Length > 0) + FlushText (true); + CodeRenderParser r = new CodeRenderParser (text, stack.Builder); + r.AddChildren (this); return; + } - IList blocks = SplitTextIntoBlocks (text); - foreach (TextBlock block in blocks) { - switch (block.Type) { - case TextBlockType.Verbatim: - this.text.Append (block.Content); - break; + int startIndex = 0, index = 0; + Match match; - case TextBlockType.Expression: - if (this.text.Length > 0) - FlushText (true); - CodeRenderParser r = new CodeRenderParser (block.Content, stack.Builder); - r.AddChildren (this); - break; + while (index > -1 && startIndex < textLen) { + match = runatServer.Match (text, index); + + if (match.Success) { + string value = match.Value; + index = match.Index; + if (index > startIndex) + this.text.Append (text.Substring (startIndex, index - startIndex)); + ParseAttributeTag (value); + index += value.Length; + startIndex = index; + } else + break; - case TextBlockType.Tag: - ParseAttributeTag (block.Content); - break; - } + if (index < textLen) + index = text.IndexOf ('<', index); + else + break; } + + this.text.Append (text.Substring (startIndex)); + //PrintLocation (location); } void FlushText () @@ -1355,7 +1331,7 @@ namespace System.Web.Compilation CheckLanguage (language); string src = (string) attributes ["src"]; if (src != null) { - if (src.Length == 0) + if (src == "") throw new ParseException (Parser, "src cannot be an empty string"); diff --git a/mcs/class/System.Web/System.Web.Compilation/ChangeLog b/mcs/class/System.Web/System.Web.Compilation/ChangeLog index fb48b024dfa..cb741c90ab4 100644 --- a/mcs/class/System.Web/System.Web.Compilation/ChangeLog +++ b/mcs/class/System.Web/System.Web.Compilation/ChangeLog @@ -9,16 +9,6 @@ try/catch, so that we can wrap the possible exception in HttpException. -2009-07-23 Marek Habersack <mhabersack@novell.com> - - * AspGenerator.cs: TextParsed takes a different approach to - post-processing text blocks now. It applies, in order, client-side - comment, tag and expression regular expressions to the text - and splits it into blocks of different types. Then the blocks are - processed accordingly. - Check for duplicate control IDs at the end of parse. Fixes bug - #524358 - 2009-06-30 Marek Habersack <mhabersack@novell.com> * AspGenerator.cs: TextParsed must remove client-side comments |