Skip to content

Commit

Permalink
Merge pull request #1661 from filipw/bugfix/equals-in-path
Browse files Browse the repository at this point in the history
do not crash on "=" in solution path
  • Loading branch information
filipw committed Dec 4, 2019
2 parents 1e2e508 + a3778bb commit 457cf8c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,7 @@ All changes to the project will be documented in this file.

## [1.34.9] - not yet released
* Do not set mono paths when running in standalone mode ([omnisharp-vscode#3410](https://github.com/OmniSharp/omnisharp-vscode/issues/3410), [omnisharp-vscode#3340](https://github.com/OmniSharp/omnisharp-vscode/issues/3340), [#1650](https://github.com/OmniSharp/omnisharp-roslyn/issues/1650), PR:[#1656](https://github.com/OmniSharp/omnisharp-roslyn/pull/1656))
* Fixed a bug where OmniSharp would crash on startup if the path contained `=` sign ([omnisharp-vscode#3436](https://github.com/OmniSharp/omnisharp-vscode/issues/3436), PR:[#1661](https://github.com/OmniSharp/omnisharp-roslyn/pull/1661))

## [1.34.8] - 2019-11-21
* Update to Roslyn `3.5.0-beta1-19571-01` (PR:[#1653](https://github.com/OmniSharp/omnisharp-roslyn/pull/1653))
Expand Down
22 changes: 20 additions & 2 deletions src/OmniSharp.Host/CommandLineApplication.cs
Expand Up @@ -36,11 +36,29 @@ public CommandLineApplication()
_debug = Application.Option("-d | --debug", "Wait for debugger to attach", CommandOptionType.NoValue);
}

public int Execute(IEnumerable<string> args)
public int Execute(string[] args)
{
// omnisharp.json arguments should not be parsed by the CLI args parser
// they will contain "=" so we should filter them out
OtherArgs = args.Where(x => x.Contains("="));
var extraArgs = new List<string>();
for (var i = 0; i < args.Length; i++)
{
// we are interested in arg with "=" if it's first
// or not-first but not preceded by "-s" or "--source"
if (args[i] != null && args[i].Contains("="))
{
if (i == 0)
{
extraArgs.Add(args[i]);
}
else if (!args[i - 1].Equals("-s", StringComparison.OrdinalIgnoreCase) && !args[i - 1].Equals("--source", StringComparison.OrdinalIgnoreCase))
{
extraArgs.Add(args[i]);
}
}
}

OtherArgs = extraArgs;
return Application.Execute(args.Except(OtherArgs).ToArray());
}

Expand Down
28 changes: 28 additions & 0 deletions tests/OmniSharp.Tests/CommandLineApplicationFacts.cs
@@ -0,0 +1,28 @@
using System.Linq;
using Xunit;

namespace OmniSharp.Tests
{
public class CommandLineApplicationFacts
{
[InlineData("-s", @"\path\to\my-solution\foo", "a=b")]
[InlineData("--source", @"\path\to\my-solution\foo", "a=b")]
[InlineData("-s", @"\path\to\my=solution\foo", "a=b")]
[InlineData("--source", @"\path\to\my=solution\foo", "a=b")]
[InlineData("a=b", "-s", @"\path\to\my-solution\foo")]
[InlineData("a=b", "--source", @"\path\to\my-solution\foo")]
[InlineData("a=b", "-s", @"\path\to\my=solution\foo")]
[InlineData("a=b", "--source", @"\path\to\my=solution\foo")]
[InlineData("a=b", null, null)]
[Theory]
public void AllowsEqualsSignInSolutionPath(string arg1, string arg2, string arg3)
{
var app = new CommandLineApplication();
app.OnExecute(() => 0);
app.Execute(new[] { arg1, arg2, arg3 });

Assert.Single(app.OtherArgs);
Assert.Equal("a=b", app.OtherArgs.First());
}
}
}

0 comments on commit 457cf8c

Please sign in to comment.