Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not crash on "=" in solution path #1661

Merged
merged 5 commits into from
Dec 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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());
}
}
}