Browse Source

fix http://community.sharpdevelop.net/forums/t/15920.aspx - VB Parse - Unhandled Exception with embedded XML

4.2
Siegfried Pammer 13 years ago committed by Daniel Grunwald
parent
commit
53feb09a06
  1. 5
      src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Lexer.cs
  2. 9
      src/Libraries/NRefactory/Test/Parser/SnippetParserTests.cs

5
src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Lexer.cs

@ -312,7 +312,10 @@ namespace ICSharpCode.NRefactory.Parser.VB
if (ch == '%' && ReaderPeek() == '>') { if (ch == '%' && ReaderPeek() == '>') {
int x = Col - 1; int x = Col - 1;
int y = Line; int y = Line;
inXmlMode = true; // in invalid code xmlModeStack might happen to be empty.
// do not set lexer to XML mode, if there was no valid XML before the inline VB code.
// fixes http://community.sharpdevelop.net/forums/t/15920.aspx
inXmlMode = xmlModeStack.Any();
ReaderRead(); ReaderRead();
return new Token(Tokens.XmlEndInlineVB, new Location(x, y), new Location(Col, Line)); return new Token(Tokens.XmlEndInlineVB, new Location(x, y), new Location(Col, Line));
} }

9
src/Libraries/NRefactory/Test/Parser/SnippetParserTests.cs

@ -26,5 +26,14 @@ namespace ICSharpCode.NRefactory.Tests
INode node = parser.Parse("Dim doc = <test><%= test %></test>"); INode node = parser.Parse("Dim doc = <test><%= test %></test>");
Assert.IsTrue(parser.Errors.Count == 0); Assert.IsTrue(parser.Errors.Count == 0);
} }
[Test]
public void InvalidXmlLiteral()
{
// ensure we don't crash on this invalid VB code
SnippetParser parser = new SnippetParser(SupportedLanguage.VBNet);
INode node = parser.Parse("<Cell StyleID=<%= print_title %>>");
Assert.IsTrue(parser.Errors.Count > 0);
}
} }
} }

Loading…
Cancel
Save