Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

389622 - Escaping special characters in sections is not working

  • Loading branch information...
commit 88372a0b4ab99dcf6415b27a5635101c09919896 1 parent 48e98c5
@anurse anurse authored
View
35 src/System.Web.Razor/Parser/HtmlMarkupParser.Section.cs
@@ -62,33 +62,24 @@ private void NestingSection(Tuple<string, string> nestingSequences)
int nesting = 1;
while (nesting > 0 && !EndOfFile)
{
+ SkipToAndParseCode(sym =>
+ sym.Type == HtmlSymbolType.Text ||
+ sym.Type == HtmlSymbolType.OpenAngle);
if (At(HtmlSymbolType.Text))
{
nesting += ProcessTextToken(nestingSequences, nesting);
+ if (CurrentSymbol != null)
+ {
+ AcceptAndMoveNext();
+ }
+ else if (nesting > 0)
+ {
+ NextToken();
+ }
}
- else if (At(HtmlSymbolType.Transition))
- {
- PutCurrentBack();
- Output(SpanKind.Markup);
- OtherParserBlock();
- continue;
- }
- else if (At(HtmlSymbolType.RazorCommentTransition))
- {
- RazorComment();
- }
- else if (ScanTagInDocumentContext())
- {
- continue;
- }
-
- if (CurrentSymbol != null)
- {
- AcceptAndMoveNext();
- }
- else if (nesting > 0)
+ else
{
- NextToken();
+ ScanTagInDocumentContext();
}
}
}
View
12 test/System.Web.Razor.Test/Parser/Html/HtmlBlockTest.cs
@@ -113,18 +113,6 @@ public void ParseBlockStopsParsingSingleLineBlockAtEOFIfNoEOLReached()
}
[Fact]
- public void ParseBlockTreatsTwoAtSignsAsEscapeSequence()
- {
- HtmlParserTestUtils.RunSingleAtEscapeTest(ParseBlockTest);
- }
-
- [Fact]
- public void ParseBlockTreatsPairsOfAtSignsAsEscapeSequence()
- {
- HtmlParserTestUtils.RunMultiAtEscapeTest(ParseBlockTest);
- }
-
- [Fact]
public void ParseBlockStopsAtMatchingCloseTagToStartTag()
{
SingleSpanBlockTest("<a><b></b></a><c></c>", "<a><b></b></a>", BlockType.Markup, SpanKind.Markup, acceptedCharacters: AcceptedCharacters.None);
View
12 test/System.Web.Razor.Test/Parser/Html/HtmlDocumentTest.cs
@@ -193,18 +193,6 @@ public void ParseDocumentNoLongerSupportsDollarOpenBraceCombination()
}
[Fact]
- public void ParseDocumentTreatsTwoAtSignsAsEscapeSequence()
- {
- HtmlParserTestUtils.RunSingleAtEscapeTest(ParseDocumentTest, lastSpanAcceptedCharacters: AcceptedCharacters.Any);
- }
-
- [Fact]
- public void ParseDocumentTreatsPairsOfAtSignsAsEscapeSequence()
- {
- HtmlParserTestUtils.RunMultiAtEscapeTest(ParseDocumentTest, lastSpanAcceptedCharacters: AcceptedCharacters.Any);
- }
-
- [Fact]
public void ParseDocumentIgnoresTagsInContentsOfScriptTag()
{
ParseDocumentTest(@"<script>foo<bar baz='@boz'></script>",
View
128 test/System.Web.Razor.Test/Parser/Html/HtmlToCodeSwitchTest.cs
@@ -196,6 +196,67 @@ public void ParseBlockGivesWhitespacePreceedingAtToCodeIfThereIsNoMarkupOnThatLi
}
[Fact]
+ public void ParseDocumentGivesWhitespacePreceedingAtToCodeIfThereIsNoMarkupOnThatLine()
+ {
+ ParseDocumentTest(@" <ul>
+ @foreach(var p in Products) {
+ <li>Product: @p.Name</li>
+ }
+ </ul>",
+ new MarkupBlock(
+ Factory.Markup(" <ul>\r\n"),
+ new StatementBlock(
+ Factory.Code(" ").AsStatement(),
+ Factory.CodeTransition(),
+ Factory.Code("foreach(var p in Products) {\r\n").AsStatement(),
+ new MarkupBlock(
+ Factory.Markup(" <li>Product: "),
+ new ExpressionBlock(
+ Factory.CodeTransition(),
+ Factory.Code("p.Name")
+ .AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
+ .Accepts(AcceptedCharacters.NonWhiteSpace)),
+ Factory.Markup("</li>\r\n").Accepts(AcceptedCharacters.None)),
+ Factory.Code(" }\r\n").AsStatement().Accepts(AcceptedCharacters.None)),
+ Factory.Markup(" </ul>")));
+ }
+
+ [Fact]
+ public void SectionContextGivesWhitespacePreceedingAtToCodeIfThereIsNoMarkupOnThatLine()
+ {
+ ParseDocumentTest(@"@section foo {
+ <ul>
+ @foreach(var p in Products) {
+ <li>Product: @p.Name</li>
+ }
+ </ul>
+}",
+ new MarkupBlock(
+ Factory.EmptyHtml(),
+ new SectionBlock(new SectionCodeGenerator("foo"),
+ Factory.CodeTransition(),
+ Factory.MetaCode("section foo {").AutoCompleteWith(null, atEndOfSpan: true),
+ new MarkupBlock(
+ Factory.Markup("\r\n <ul>\r\n"),
+ new StatementBlock(
+ Factory.Code(" ").AsStatement(),
+ Factory.CodeTransition(),
+ Factory.Code("foreach(var p in Products) {\r\n").AsStatement(),
+ new MarkupBlock(
+ Factory.Markup(" <li>Product: "),
+ new ExpressionBlock(
+ Factory.CodeTransition(),
+ Factory.Code("p.Name")
+ .AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
+ .Accepts(AcceptedCharacters.NonWhiteSpace)),
+ Factory.Markup("</li>\r\n").Accepts(AcceptedCharacters.None)),
+ Factory.Code(" }\r\n").AsStatement().Accepts(AcceptedCharacters.None)),
+ Factory.Markup(" </ul>\r\n")),
+ Factory.MetaCode("}").Accepts(AcceptedCharacters.None)),
+ Factory.EmptyHtml()));
+ }
+
+ [Fact]
public void CSharpCodeParserDoesNotAcceptLeadingOrTrailingWhitespaceInDesignMode()
{
ParseBlockTest(@" <ul>
@@ -218,5 +279,72 @@ public void CSharpCodeParserDoesNotAcceptLeadingOrTrailingWhitespaceInDesignMode
Factory.Markup("\r\n </ul>").Accepts(AcceptedCharacters.None)),
designTimeParser: true);
}
+
+ // Tests for "@@" escape sequence:
+ [Fact]
+ public void ParseBlockTreatsTwoAtSignsAsEscapeSequence()
+ {
+ HtmlParserTestUtils.RunSingleAtEscapeTest(ParseBlockTest);
+ }
+
+ [Fact]
+ public void ParseBlockTreatsPairsOfAtSignsAsEscapeSequence()
+ {
+ HtmlParserTestUtils.RunMultiAtEscapeTest(ParseBlockTest);
+ }
+
+ [Fact]
+ public void ParseDocumentTreatsTwoAtSignsAsEscapeSequence()
+ {
+ HtmlParserTestUtils.RunSingleAtEscapeTest(ParseDocumentTest, lastSpanAcceptedCharacters: AcceptedCharacters.Any);
+ }
+
+ [Fact]
+ public void ParseDocumentTreatsPairsOfAtSignsAsEscapeSequence()
+ {
+ HtmlParserTestUtils.RunMultiAtEscapeTest(ParseDocumentTest, lastSpanAcceptedCharacters: AcceptedCharacters.Any);
+ }
+
+ [Fact]
+ public void SectionBodyTreatsTwoAtSignsAsEscapeSequence()
+ {
+ ParseDocumentTest("@section Foo { <foo>@@bar</foo> }",
+ new MarkupBlock(
+ Factory.EmptyHtml(),
+ new SectionBlock(new SectionCodeGenerator("Foo"),
+ Factory.CodeTransition(),
+ Factory.MetaCode("section Foo {").AutoCompleteWith(null, atEndOfSpan: true),
+ new MarkupBlock(
+ Factory.Markup(" <foo>"),
+ Factory.Markup("@").Hidden(),
+ Factory.Markup("@bar</foo> ")),
+ Factory.MetaCode("}").Accepts(AcceptedCharacters.None)),
+ Factory.EmptyHtml()));
+ }
+
+ [Fact]
+ public void SectionBodyTreatsPairsOfAtSignsAsEscapeSequence()
+ {
+ ParseDocumentTest("@section Foo { <foo>@@@@@bar</foo> }",
+ new MarkupBlock(
+ Factory.EmptyHtml(),
+ new SectionBlock(new SectionCodeGenerator("Foo"),
+ Factory.CodeTransition(),
+ Factory.MetaCode("section Foo {").AutoCompleteWith(null, atEndOfSpan: true),
+ new MarkupBlock(
+ Factory.Markup(" <foo>"),
+ Factory.Markup("@").Hidden(),
+ Factory.Markup("@"),
+ Factory.Markup("@").Hidden(),
+ Factory.Markup("@"),
+ new ExpressionBlock(
+ Factory.CodeTransition(),
+ Factory.Code("bar")
+ .AsImplicitExpression(CSharpCodeParser.DefaultKeywords)
+ .Accepts(AcceptedCharacters.NonWhiteSpace)),
+ Factory.Markup("</foo> ")),
+ Factory.MetaCode("}").Accepts(AcceptedCharacters.None)),
+ Factory.EmptyHtml()));
+ }
}
}
View
50 test/System.Web.Razor.Test/Parser/VB/VBSectionTest.cs
@@ -221,5 +221,55 @@ public void ParseSectionAllowsEndSectionInVBExpression()
Factory.MetaCode("End Section").Accepts(AcceptedCharacters.None)),
Factory.EmptyHtml()));
}
+
+ // These are tests that are normally in HtmlToCodeSwitchTest, but we want to verify them for VB
+ // since VB has slightly different section terminating behavior which follow slightly different
+ // code paths
+
+ [Fact]
+ public void SectionBodyTreatsTwoAtSignsAsEscapeSequence()
+ {
+ ParseDocumentTest(@"@Section Foo
+ <foo>@@bar</foo>
+End Section",
+ new MarkupBlock(
+ Factory.EmptyHtml(),
+ new SectionBlock(new SectionCodeGenerator("Foo"),
+ Factory.CodeTransition(),
+ Factory.MetaCode("Section Foo").AutoCompleteWith(null),
+ new MarkupBlock(
+ Factory.Markup("\r\n <foo>"),
+ Factory.Markup("@").Hidden(),
+ Factory.Markup("@bar</foo>\r\n")),
+ Factory.MetaCode("End Section").Accepts(AcceptedCharacters.None)),
+ Factory.EmptyHtml()));
+ }
+
+ [Fact]
+ public void SectionBodyTreatsPairsOfAtSignsAsEscapeSequence()
+ {
+ ParseDocumentTest(@"@Section Foo
+ <foo>@@@@@bar</foo>
+End Section",
+ new MarkupBlock(
+ Factory.EmptyHtml(),
+ new SectionBlock(new SectionCodeGenerator("Foo"),
+ Factory.CodeTransition(),
+ Factory.MetaCode("Section Foo").AutoCompleteWith(null),
+ new MarkupBlock(
+ Factory.Markup("\r\n <foo>"),
+ Factory.Markup("@").Hidden(),
+ Factory.Markup("@"),
+ Factory.Markup("@").Hidden(),
+ Factory.Markup("@"),
+ new ExpressionBlock(
+ Factory.CodeTransition(),
+ Factory.Code("bar")
+ .AsImplicitExpression(VBCodeParser.DefaultKeywords)
+ .Accepts(AcceptedCharacters.NonWhiteSpace)),
+ Factory.Markup("</foo>\r\n")),
+ Factory.MetaCode("End Section").Accepts(AcceptedCharacters.None)),
+ Factory.EmptyHtml()));
+ }
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.