//
using System;
using System.Collections;
+using System.Collections.Generic;
using System.CodeDom.Compiler;
using System.Globalization;
using System.IO;
using System.Web.UI.HtmlControls;
using System.Web.Util;
-#if NET_2_0
-using System.Collections.Generic;
-#endif
-
namespace System.Web.Compilation
{
class BuilderLocation
if (tags.Count == 0)
return false;
- return 0 == String.Compare (tagid, (string) tags.Peek (), true, CultureInfo.InvariantCulture);
+ return 0 == String.Compare (tagid, (string) tags.Peek (), true, Helpers.InvariantCulture);
}
public int Count {
class AspGenerator
{
-#if NET_2_0
const int READ_BUFFER_SIZE = 8192;
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 |
bool inForm;
bool useOtherTags;
TagType lastTag;
-#if NET_2_0
AspComponentFoundry componentFoundry;
Stream inputStream;
{
this.componentFoundry = componentFoundry;
}
-#endif
public AspGenerator (TemplateParser tparser)
{
this.tparser = tparser;
text = new StringBuilder ();
stack = new BuilderLocationStack ();
-
-#if !NET_2_0
- rootBuilder = new RootBuilder (tparser);
- tparser.RootBuilder = rootBuilder;
- stack.Push (rootBuilder, null);
-#endif
pstack = new ParserStack ();
}
get { return pstack.Filename; }
}
-#if NET_2_0
PageParserFilter PageParserFilter {
get {
if (tparser == null)
if (matches == null || matches.Count == 0)
return null;
- string wantedDirectiveName = tparser.DefaultDirectiveName.ToLower ();
+ string wantedDirectiveName = tparser.DefaultDirectiveName.ToLower (Helpers.InvariantCulture);
string directiveName;
GroupCollection groups;
CaptureCollection ccNames;
if (String.IsNullOrEmpty (directiveName))
continue;
- if (String.Compare (directiveName.ToLower (), wantedDirectiveName, StringComparison.Ordinal) != 0)
+ if (String.Compare (directiveName.ToLower (Helpers.InvariantCulture), wantedDirectiveName, StringComparison.Ordinal) != 0)
continue;
var loc = new Location (null);
stack.Push (rootBuilder, null);
tparser.RootBuilder = rootBuilder;
}
-#endif
BaseCompiler GetCompilerFromType ()
{
if (type == typeof (UserControlParser))
return new UserControlCompiler ((UserControlParser) tparser);
-#if NET_2_0
+
if (type == typeof(MasterPageParser))
return new MasterPageCompiler ((MasterPageParser) tparser);
-#endif
throw new Exception ("Got type: " + type);
}
parser.Error += new ParseErrorHandler (ParseError);
parser.TagParsed += new TagParsedHandler (TagParsed);
parser.TextParsed += new TextParsedHandler (TextParsed);
-#if NET_2_0
parser.ParsingComplete += new ParsingCompleteHandler (ParsingCompleted);
tparser.AspGenerator = this;
CreateRootBuilder (inputStream, filename);
-#endif
+
if (!pstack.Push (parser))
throw new ParseException (Location, "Infinite recursion detected including file: " + filename);
}
}
-#if NET_2_0
void InitParser (string filename)
{
StreamReader reader = new StreamReader (filename, WebEncoding.FileEncoding);
InitParser (reader, filename);
}
-#endif
void CheckForDuplicateIds (ControlBuilder root, Stack scopes)
{
return;
if (scopes == null)
- scopes = new Stack ();
-
-#if NET_2_0
+ scopes = new Stack ();
+
Dictionary <string, bool> ids;
-#else
- Hashtable ids;
-#endif
if (scopes.Count == 0 || root.IsNamingContainer) {
-#if NET_2_0
ids = new Dictionary <string, bool> (StringComparer.Ordinal);
-#else
- ids = new Hashtable ();
-#endif
scopes.Push (ids);
} else {
-#if NET_2_0
ids = scopes.Peek () as Dictionary <string, bool>;
-#else
- ids = scopes.Peek () as Hashtable;
-#endif
}
if (ids == null)
public void Parse (string file)
{
-#if ONLY_1_1
- Parse (file, true);
-#else
Parse (file, false);
-#endif
}
public void Parse (TextReader reader, string filename, bool doInitParser)
if (text.Length > 0)
FlushText ();
-#if NET_2_0
tparser.MD5Checksum = pstack.Parser.MD5Checksum;
-#endif
pstack.Pop ();
#if DEBUG
public void Parse (Stream stream, string filename, bool doInitParser)
{
-#if NET_2_0
inputStream = stream;
-#endif
Parse (new StreamReader (stream, WebEncoding.FileEncoding), filename, doInitParser);
}
public void Parse ()
{
-#if NET_2_0
string inputFile = tparser.InputFile;
TextReader inputReader = tparser.Reader;
if (inputReader != null)
inputReader.Close ();
}
-#else
- Parse (Path.GetFullPath (tparser.InputFile));
-#endif
}
internal static void AddTypeToCache (ArrayList dependencies, string inputFile, Type type)
}
Parse ();
-
BaseCompiler compiler = GetCompilerFromType ();
type = compiler.GetCompiledType ();
void ParseAttributeTag (string code, ILocation location)
{
- AspParser parser = new AspParser ("@@attribute_tag@@", new StringReader (code), location.BeginLine - 1, location as AspParser);
+ AspParser outerParser = location as AspParser;
+ int positionOffset = outerParser != null ? outerParser.BeginPosition : 0;
+ AspParser parser = new AspParser ("@@attribute_tag@@", new StringReader (code), location.BeginLine - 1, positionOffset, outerParser);
parser.Error += new ParseErrorHandler (ParseError);
parser.TagParsed += new TagParsedHandler (TagParsed);
parser.TextParsed += new TextParsedHandler (TextParsed);
FlushText ();
}
-#if NET_2_0
void ParsingCompleted ()
{
PageParserFilter pfilter = PageParserFilter;
pfilter.ParseComplete (RootBuilder);
}
-#endif
void CheckIfIncludeFileIsSecure (string filePath)
{
if (exception != null || !StrUtils.StartsWith (newdir, HttpRuntime.AppDomainAppPath))
throw new ParseException (Location, "Files above the application's root directory cannot be included.");
}
+
+ string ChopOffTagStart (ILocation location, string content, string tagid)
+ {
+ string tagstart = '<' + tagid;
+ if (content.StartsWith (tagstart)) {
+ TextParsed (location, tagstart);
+ content = content.Substring (tagstart.Length);
+ }
+
+ return content;
+ }
void TagParsed (ILocation location, TagType tagtype, string tagid, TagAttributes attributes)
{
if (text.Length != 0)
FlushText (lastTag == TagType.CodeRender);
- if (0 == String.Compare (tagid, "script", true, CultureInfo.InvariantCulture)) {
+ if (0 == String.Compare (tagid, "script", true, Helpers.InvariantCulture)) {
bool in_script = (inScript || ignore_text);
if (in_script) {
if (ProcessScript (tagtype, attributes))
{
string plainText = location.PlainText;
if (!ProcessTagsInAttributes (location, tagid, attributes, TagType.Tag))
- TextParsed (location, plainText);
+ TextParsed (location, ChopOffTagStart (location, plainText, tagid));
}
break;
case TagType.Close:
if (!ProcessTag (location, tagid, attributes, tagtype, out tagIgnored) && !tagIgnored) {
string plainText = location.PlainText;
if (!ProcessTagsInAttributes (location, tagid, attributes, TagType.SelfClosing))
- TextParsed (location, plainText);
+ TextParsed (location, ChopOffTagStart (location, plainText, tagid));
} else if (stack.Count != count) {
CloseControl (tagid);
}
if (isvirtual) {
bool parsed = false;
-#if NET_2_0
VirtualPathProvider vpp = HostingEnvironment.VirtualPathProvider;
if (vpp.FileExists (file)) {
parsed = true;
}
}
-#endif
if (!parsed)
Parse (tparser.MapPath (file), true);
for (int idx = otags.Count - 1; idx >= 0; idx--) {
string otagid = (string) otags [idx];
- if (0 == String.Compare (tagid, otagid, true, CultureInfo.InvariantCulture)) {
+ if (0 == String.Compare (tagid, otagid, true, Helpers.InvariantCulture)) {
do {
otags.RemoveAt (idx);
} while (otags.Count - 1 >= idx);
return !text.EndsWith ("/>");
}
-#if NET_2_0
- List <TextBlock>
-#else
- ArrayList
-#endif
- FindRegexBlocks (Regex rxStart, Regex rxEnd, CheckBlockEnd checkEnd, IList blocks, TextBlockType typeForMatches, bool discardBlocks)
+ List <TextBlock> FindRegexBlocks (Regex rxStart, Regex rxEnd, CheckBlockEnd checkEnd, IList blocks, TextBlockType typeForMatches, bool discardBlocks)
{
-#if NET_2_0
var ret = new List <TextBlock> ();
-#else
- ArrayList ret = new ArrayList ();
-#endif
-
foreach (TextBlock block in blocks) {
if (block.Type != TextBlockType.Verbatim) {
ret.Add (block);
IList SplitTextIntoBlocks (string text)
{
-#if NET_2_0
var ret = new List <TextBlock> ();
-#else
- ArrayList ret = new ArrayList ();
-#endif
ret.Add (new TextBlock (TextBlockType.Verbatim, text));
ret = FindRegexBlocks (clientCommentRegex, null, null, ret, TextBlockType.Comment, false);
FlushText (true);
return;
}
-
+
IList blocks = SplitTextIntoBlocks (text);
foreach (TextBlock block in blocks) {
switch (block.Type) {
case TextBlockType.Comment: {
this.text.Append ("<!--");
FlushText (true);
- AspParser parser = new AspParser ("@@comment_code@@",
- new StringReader (block.Content.Substring (4, block.Length - 7)),
- location.BeginLine - 1,
- location as AspParser);
+ string blockToParse = block.Content.Substring (4, block.Length - 7);
+ bool condEndif;
+ if (blockToParse.EndsWith ("<![endif]")) {
+ blockToParse = blockToParse.Substring (0, blockToParse.Length - 9);
+ condEndif = true;
+ } else
+ condEndif = false;
+
+ AspParser outerParser = location as AspParser;
+ int positionOffset = outerParser != null ? outerParser.BeginPosition : 0;
+ AspParser parser = new AspParser ("@@comment_code@@", new StringReader (blockToParse), location.BeginLine - 1, positionOffset, outerParser);
parser.Error += new ParseErrorHandler (ParseError);
parser.TagParsed += new TagParsedHandler (TagParsed);
parser.TextParsed += new TextParsedHandler (TextParsed);
parser.Parse ();
+ if (condEndif)
+ this.text.Append ("<![endif]");
this.text.Append ("-->");
FlushText (true);
break;
return;
if (inScript) {
-#if NET_2_0
PageParserFilter pfilter = PageParserFilter;
if (pfilter != null && !pfilter.ProcessCodeConstruct (CodeConstructType.ScriptTag, t))
return;
-#endif
+
tparser.Scripts.Add (new ServerSideScript (t, new System.Web.Compilation.Location (tparser.Location)));
return;
}
}
}
-#if NET_2_0
bool BuilderHasOtherThan (Type type, ControlBuilder cb)
{
ArrayList al = cb.OtherTags;
return true;
}
-#endif
public void AddControl (Type type, IDictionary attributes)
{
{
ignored = false;
if (isApplication) {
- if (String.Compare (tagid, "object", true, CultureInfo.InvariantCulture) != 0)
+ if (String.Compare (tagid, "object", true, Helpers.InvariantCulture) != 0)
throw new ParseException (location, "Invalid tag for application file.");
}
ControlBuilder parent = stack.Builder;
ControlBuilder builder = null;
if (parent != null && parent.ControlType == typeof (HtmlTable) &&
- (String.Compare (tagid, "thead", true, CultureInfo.InvariantCulture) == 0 ||
- String.Compare (tagid, "tbody", true, CultureInfo.InvariantCulture) == 0)) {
+ (String.Compare (tagid, "thead", true, Helpers.InvariantCulture) == 0 ||
+ String.Compare (tagid, "tbody", true, Helpers.InvariantCulture) == 0)) {
ignored = true;
return true;
}
string plainText = location.PlainText;
if (!runatServer && plainText.IndexOf ("<%$") == -1&& plainText.IndexOf ("<%") > -1)
return false;
-#if NET_2_0
+
PageParserFilter pfilter = PageParserFilter;
if (pfilter != null && !pfilter.AllowControl (builder.ControlType, builder))
throw new ParseException (Location, "Control type '" + builder.ControlType + "' not allowed.");
if (!OtherControlsAllowed (builder))
throw new ParseException (Location, "Only Content controls are allowed directly in a content page that contains Content controls.");
-#endif
builder.Location = location;
builder.ID = htable ["id"] as string;
Parser.VerbatimID = "script";
javascript = true;
}
- TextParsed (location, location.PlainText);
+ string content = location.PlainText;
+ /* HACK, HACK, HACK */
+ if (content.StartsWith ("<script")) {
+ TextParsed (location, "<script");
+ content = content.Substring (7);
+ }
+
+ TextParsed (location, content);
return true;
}
}
{
ControlBuilder current = stack.Builder;
string btag = current.OriginalTagName;
- if (String.Compare (btag, "tbody", true, CultureInfo.InvariantCulture) != 0 &&
- String.Compare (tagid, "tbody", true, CultureInfo.InvariantCulture) == 0) {
+ if (String.Compare (btag, "tbody", true, Helpers.InvariantCulture) != 0 &&
+ String.Compare (tagid, "tbody", true, Helpers.InvariantCulture) == 0) {
if (!current.ChildrenAsProperties) {
try {
TextParsed (location, location.PlainText);
return true;
}
- if (current.ControlType == typeof (HtmlTable) && String.Compare (tagid, "thead", true, CultureInfo.InvariantCulture) == 0)
+ if (current.ControlType == typeof (HtmlTable) && String.Compare (tagid, "thead", true, Helpers.InvariantCulture) == 0)
return true;
- if (0 != String.Compare (tagid, btag, true, CultureInfo.InvariantCulture))
+ if (0 != String.Compare (tagid, btag, true, Helpers.InvariantCulture))
return false;
// if (current is TemplateBuilder)
return true;
}
-#if NET_2_0
CodeConstructType MapTagTypeToConstructType (TagType tagtype)
{
switch (tagtype) {
}
}
-#endif
bool ProcessCode (TagType tagtype, string code, ILocation location)
{
-#if NET_2_0
PageParserFilter pfilter = PageParserFilter;
// LAMESPEC:
//
//
if (pfilter != null && (!pfilter.AllowCode || pfilter.ProcessCodeConstruct (MapTagTypeToConstructType (tagtype), code)))
return true;
-#endif
+
ControlBuilder b = null;
if (tagtype == TagType.CodeRender)
b = new CodeRenderBuilder (code, false, location);
if (lang == null || lang == "")
return;
- if (String.Compare (lang, tparser.Language, true, CultureInfo.InvariantCulture) == 0)
+ if (String.Compare (lang, tparser.Language, true, Helpers.InvariantCulture) == 0)
return;
-#if NET_2_0
CompilationSection section = (CompilationSection) WebConfigurationManager.GetWebApplicationSection ("system.web/compilation");
if (section.Compilers[tparser.Language] != section.Compilers[lang])
-#else
- CompilationConfiguration cfg = CompilationConfiguration.GetInstance (HttpContext.Current);
- if (!cfg.Compilers.CompareLanguages (tparser.Language, lang))
-#endif
throw new ParseException (Location,
String.Format ("Trying to mix language '{0}' and '{1}'.",
tparser.Language, lang));
void DoParse (string str)
{
- AspParser parser = new AspParser ("@@code_render@@", new StringReader (str), location.BeginLine - 1, location as AspParser);
+ AspParser outerParser = location as AspParser;
+ int positionOffset = outerParser != null ? outerParser.BeginPosition : 0;
+ AspParser parser = new AspParser ("@@code_render@@", new StringReader (str), location.BeginLine - 1, positionOffset, outerParser);
parser.Error += new ParseErrorHandler (ParseError);
parser.TagParsed += new TagParsedHandler (TagParsed);
parser.TextParsed += new TextParsedHandler (TextParsed);