diff --git a/src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RubyAstWalker.cs b/src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RubyAstWalker.cs index b13dd25e80..9b398b52ed 100644 --- a/src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RubyAstWalker.cs +++ b/src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RubyAstWalker.cs @@ -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 base.Walk(node); } + bool HasArguments(MethodCall node) + { + return (node.Arguments != null) && (!node.Arguments.IsEmpty); + } + string GetRequireString(Expression[] expressions) { foreach (Expression expression in expressions) { diff --git a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Parsing/ParseRequireFollowedByCommentTestFixture.cs b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Parsing/ParseRequireFollowedByCommentTestFixture.cs new file mode 100644 index 0000000000..ba4773aa86 --- /dev/null +++ b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Parsing/ParseRequireFollowedByCommentTestFixture.cs @@ -0,0 +1,39 @@ +// +// +// +// +// $Revision$ +// + +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 +{ + /// + /// 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. + /// + [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); + } + } +} diff --git a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/RubyBinding.Tests.csproj b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/RubyBinding.Tests.csproj index 6242cd0b12..c9b6962107 100644 --- a/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/RubyBinding.Tests.csproj +++ b/src/AddIns/BackendBindings/Ruby/RubyBinding/Test/RubyBinding.Tests.csproj @@ -312,6 +312,7 @@ +