would cause an error because there's no + // matching end
tag in the template block scope and therefore doesn't make sense as a tag helper. + BuildMalformedTagHelpers(_tagStack.Count - activeTagHelpers, context); + + Debug.Assert(activeTagHelpers == _tagStack.Count); + } + BuildCurrentlyTrackedBlock(); } - private void ValidateRewrittenSyntaxTree(RewritingContext context) + private bool TryRewriteTagHelper(Block tagBlock, RewritingContext context) { - // If the blockStack still has elements in it that means there's at least one malformed TagHelper block in - // the document, that's the only way we can have a non-zero _blockStack.Count. - if (_blockStack.Count != 0) + // TODO: Fully handle malformed tags: https://github.com/aspnet/Razor/issues/104 + + // Get tag name of the current block (doesn't matter if it's an end or start tag) + var tagName = GetTagName(tagBlock); + + // Could not determine tag name, it can't be a TagHelper, continue on and track the element. + if (tagName == null) { - // We reverse the children so we can search from the back to the front for the TagHelper that is - // malformed. - var candidateChildren = _currentBlock.Children.Reverse(); - var malformedTagHelper = candidateChildren.OfType",
+ new MarkupBlock(
+ new MarkupTagHelperBlock("p",
+ new Dictionary
+ {
+ {
+ " ",
+ new MarkupBlock(
+ blockFactory.MarkupTagBlock("<"),
+ blockFactory.MarkupTagBlock("<"),
+ blockFactory.MarkupTagBlock("
", new MarkupBlock( new MarkupTagHelperBlock("p", - new Dictionary
Hello World
Hello World
Hello
World
", @@ -180,8 +622,12 @@ namespace Microsoft.AspNet.Razor.Test.TagHelpers { "style", factory.Markup("color:red;") } }, factory.Markup("World")))), - new RazorError(string.Format(CultureInfo.InvariantCulture, errorFormat, "p"), - SourceLocation.Zero) + new RazorError[] + { + new RazorError( + string.Format(CultureInfo.InvariantCulture, malformedErrorFormat, "p"), + SourceLocation.Zero) + } }; } } @@ -191,9 +637,9 @@ namespace Microsoft.AspNet.Razor.Test.TagHelpers public void TagHelperParseTreeRewriter_CreatesErrorForIncompleteTagHelper( string documentContent, MarkupBlock expectedOutput, - RazorError expectedError) + RazorError[] expectedErrors) { - RunParseTreeRewriterTest(documentContent, expectedOutput, new[] { expectedError }, "strong", "p"); + RunParseTreeRewriterTest(documentContent, expectedOutput, expectedErrors, "strong", "p"); } public static TheoryData