Browse Source

Fixed a null reference exception that occurs when the Ruby fold parser attempted to parse a require expression without any parameters following it.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@5368 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Matt Ward 16 years ago
parent
commit
caf7c4a833
  1. 7
      src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RubyAstWalker.cs
  2. 39
      src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Parsing/ParseRequireFollowedByCommentTestFixture.cs
  3. 1
      src/AddIns/BackendBindings/Ruby/RubyBinding/Test/RubyBinding.Tests.csproj

7
src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RubyAstWalker.cs

@ -45,7 +45,7 @@ namespace ICSharpCode.RubyBinding @@ -45,7 +45,7 @@ namespace ICSharpCode.RubyBinding
protected override void Walk(MethodCall node)
{
if (node.MethodName == "require") {
if (!node.Arguments.IsEmpty) {
if (HasArguments(node)) {
string requireString = GetRequireString(node.Arguments.Expressions);
if (requireString != null) {
AddUsing(requireString);
@ -55,6 +55,11 @@ namespace ICSharpCode.RubyBinding @@ -55,6 +55,11 @@ namespace ICSharpCode.RubyBinding
base.Walk(node);
}
bool HasArguments(MethodCall node)
{
return (node.Arguments != null) && (!node.Arguments.IsEmpty);
}
string GetRequireString(Expression[] expressions)
{
foreach (Expression expression in expressions) {

39
src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Parsing/ParseRequireFollowedByCommentTestFixture.cs

@ -0,0 +1,39 @@ @@ -0,0 +1,39 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using ICSharpCode.RubyBinding;
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.TextEditor.Document;
using NUnit.Framework;
using RubyBinding.Tests;
namespace RubyBinding.Tests.Parsing
{
/// <summary>
/// A string of the form "require #" would cause a null reference exception since the ruby ast walker tries
/// to use the MethodCall's Argument which is null.
/// </summary>
[TestFixture]
public class ParseRequireFollowedByCommentTestFixture
{
[Test]
public void ParseDoesNotThrowNullReferenceException()
{
string ruby = "require #";
DefaultProjectContent projectContent = new DefaultProjectContent();
RubyParser parser = new RubyParser();
ICompilationUnit unit = null;
Assert.DoesNotThrow(delegate { unit = parser.Parse(projectContent, @"C:\test.rb", ruby); });
Assert.IsNotNull(unit);
}
}
}

1
src/AddIns/BackendBindings/Ruby/RubyBinding/Test/RubyBinding.Tests.csproj

@ -312,6 +312,7 @@ @@ -312,6 +312,7 @@
<Compile Include="Parsing\ParseClassWithCtorTestFixture.cs" />
<Compile Include="Parsing\ParseInvalidRubyCodeTestFixture.cs" />
<Compile Include="Parsing\ParseMethodsWithNoClassTestFixture.cs" />
<Compile Include="Parsing\ParseRequireFollowedByCommentTestFixture.cs" />
<Compile Include="Parsing\ParseRequireTestFixture.cs" />
<Compile Include="Parsing\ParseSingleClassTestFixture.cs" />
<Compile Include="RubyAddInOptionsTestFixture.cs" />

Loading…
Cancel
Save