Browse Source

Fix SD2-1584 - VB .NET snippet parser crashes on invalid syntax

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4883 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 16 years ago
parent
commit
1bab5625a5
  1. 11
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs
  2. 4
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG
  3. 1
      src/Libraries/NRefactory/Test/NRefactoryTests.csproj
  4. 26
      src/Libraries/NRefactory/Test/Parser/SnippetParserTests.cs

11
src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs

@ -1854,18 +1854,17 @@ out implementsClause); @@ -1854,18 +1854,17 @@ out implementsClause);
}
case 2: case 45: case 49: case 51: case 52: case 53: case 54: case 57: case 74: case 91: case 94: case 103: case 108: case 113: case 120: case 126: case 130: case 133: case 156: case 162: case 169: case 188: case 197: case 198: case 208: case 209: case 215: {
#line 1026 "VBNET.ATG"
Location startPos = t.Location;
#line 1028 "VBNET.ATG"
#line 1027 "VBNET.ATG"
m.Check(Modifiers.Fields);
FieldDeclaration fd = new FieldDeclaration(attributes, null, m.Modifier);
fd.StartLocation = m.GetDeclarationLocation(startPos);
IdentifierForFieldDeclaration();
#line 1032 "VBNET.ATG"
#line 1030 "VBNET.ATG"
string name = t.val;
#line 1031 "VBNET.ATG"
fd.StartLocation = m.GetDeclarationLocation(t.Location);
VariableDeclaratorPartAfterIdentifier(
#line 1033 "VBNET.ATG"
variableDeclarators, name);

4
src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG

@ -1023,13 +1023,13 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes> @@ -1023,13 +1023,13 @@ StructureMemberDecl<ModifierList m, List<AttributeSection> attributes>
.)
EndOfStmt
| /* 9.6 */
(. Location startPos = t.Location; .)
(.
m.Check(Modifiers.Fields);
FieldDeclaration fd = new FieldDeclaration(attributes, null, m.Modifier);
fd.StartLocation = m.GetDeclarationLocation(startPos);
.)
IdentifierForFieldDeclaration (. string name = t.val; .)
(. fd.StartLocation = m.GetDeclarationLocation(t.Location); .)
VariableDeclaratorPartAfterIdentifier<variableDeclarators, name>
{ "," VariableDeclarator<variableDeclarators> }
EndOfStmt

1
src/Libraries/NRefactory/Test/NRefactoryTests.csproj

@ -80,6 +80,7 @@ @@ -80,6 +80,7 @@
<Compile Include="Parser\Expressions\StackAllocExpressionTests.cs" />
<Compile Include="Parser\GlobalScope\UsingDeclarationTests.cs" />
<Compile Include="Parser\GlobalScope\TypeDeclarationTests.cs" />
<Compile Include="Parser\SnippetParserTests.cs" />
<Compile Include="Parser\TypeLevel\ConstructorDeclarationTests.cs" />
<Compile Include="Parser\TypeLevel\EventDeclarationTests.cs" />
<Compile Include="Parser\TypeLevel\FieldDeclarationTests.cs" />

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

@ -0,0 +1,26 @@ @@ -0,0 +1,26 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
using ICSharpCode.NRefactory.Ast;
using System;
using NUnit.Framework;
namespace ICSharpCode.NRefactory.Tests
{
[TestFixture]
public class SnippetParserTests
{
[Test]
public void InvalidExpressionSyntax()
{
// SD2-1584: ensure we don't crash on this invalid VB code
SnippetParser parser = new SnippetParser(SupportedLanguage.VBNet);
INode node = parser.Parse("i == 5");
Assert.IsTrue(parser.Errors.Count > 0);
}
}
}
Loading…
Cancel
Save