From b7d8b3082852d31f8b8adf5264a6770f538d39b7 Mon Sep 17 00:00:00 2001 From: filipw Date: Mon, 2 Dec 2019 11:46:44 +0100 Subject: [PATCH 1/5] do not process "=" in solution path --- src/OmniSharp.Host/CommandLineApplication.cs | 22 ++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/OmniSharp.Host/CommandLineApplication.cs b/src/OmniSharp.Host/CommandLineApplication.cs index 81545109b8..b99b3320e4 100644 --- a/src/OmniSharp.Host/CommandLineApplication.cs +++ b/src/OmniSharp.Host/CommandLineApplication.cs @@ -36,11 +36,29 @@ public CommandLineApplication() _debug = Application.Option("-d | --debug", "Wait for debugger to attach", CommandOptionType.NoValue); } - public int Execute(IEnumerable 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(); + 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].Contains("=")) + { + if (i == 0) + { + extraArgs.Add(args[i]); + } + else if (!args[i - 1].Equals("-s", StringComparison.OrdinalIgnoreCase) && !args[i - 1].Equals("-s", StringComparison.OrdinalIgnoreCase)) + { + extraArgs.Add(args[i]); + } + } + } + + OtherArgs = extraArgs; return Application.Execute(args.Except(OtherArgs).ToArray()); } From 5118e0a6a0eaac4c45f4705314951e8b8a672c3e Mon Sep 17 00:00:00 2001 From: filipw Date: Mon, 2 Dec 2019 16:05:39 +0100 Subject: [PATCH 2/5] added null check --- src/OmniSharp.Host/CommandLineApplication.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OmniSharp.Host/CommandLineApplication.cs b/src/OmniSharp.Host/CommandLineApplication.cs index b99b3320e4..aecc816a45 100644 --- a/src/OmniSharp.Host/CommandLineApplication.cs +++ b/src/OmniSharp.Host/CommandLineApplication.cs @@ -45,13 +45,13 @@ public int Execute(string[] args) { // we are interested in arg with "=" if it's first // or not-first but not preceded by "-s" or "--source" - if (args[i].Contains("=")) + 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("-s", StringComparison.OrdinalIgnoreCase)) + else if (!args[i - 1].Equals("-s", StringComparison.OrdinalIgnoreCase) && !args[i - 1].Equals("--source", StringComparison.OrdinalIgnoreCase)) { extraArgs.Add(args[i]); } From 3f4bcd40be8a4726178f0a3fa40cfa9f78364bb1 Mon Sep 17 00:00:00 2001 From: filipw Date: Mon, 2 Dec 2019 16:05:57 +0100 Subject: [PATCH 3/5] added tests for CommandLineApplication --- .../OmniSharpEnvironmentFacts.cs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/OmniSharp.Tests/OmniSharpEnvironmentFacts.cs b/tests/OmniSharp.Tests/OmniSharpEnvironmentFacts.cs index 028596e59b..43bfe6e373 100644 --- a/tests/OmniSharp.Tests/OmniSharpEnvironmentFacts.cs +++ b/tests/OmniSharp.Tests/OmniSharpEnvironmentFacts.cs @@ -1,10 +1,34 @@ using Microsoft.Extensions.Logging; using OmniSharp.Services; +using System.Linq; using TestUtility; 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()); + } + } + public class OmniSharpEnvironmentFacts { [Fact] From a4ceaf8213302eb778e8bd8fba7a14e5c4e2cc98 Mon Sep 17 00:00:00 2001 From: filipw Date: Mon, 2 Dec 2019 16:06:26 +0100 Subject: [PATCH 4/5] moved CommandLineApplicationFacts to a dedicated file --- .../CommandLineApplicationFacts.cs | 28 +++++++++++++++++++ .../OmniSharpEnvironmentFacts.cs | 24 ---------------- 2 files changed, 28 insertions(+), 24 deletions(-) create mode 100644 tests/OmniSharp.Tests/CommandLineApplicationFacts.cs diff --git a/tests/OmniSharp.Tests/CommandLineApplicationFacts.cs b/tests/OmniSharp.Tests/CommandLineApplicationFacts.cs new file mode 100644 index 0000000000..5d75037bd3 --- /dev/null +++ b/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()); + } + } +} diff --git a/tests/OmniSharp.Tests/OmniSharpEnvironmentFacts.cs b/tests/OmniSharp.Tests/OmniSharpEnvironmentFacts.cs index 43bfe6e373..028596e59b 100644 --- a/tests/OmniSharp.Tests/OmniSharpEnvironmentFacts.cs +++ b/tests/OmniSharp.Tests/OmniSharpEnvironmentFacts.cs @@ -1,34 +1,10 @@ using Microsoft.Extensions.Logging; using OmniSharp.Services; -using System.Linq; using TestUtility; 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()); - } - } - public class OmniSharpEnvironmentFacts { [Fact] From a3778bbcf40ddaad6ce3afef4579867638ff3071 Mon Sep 17 00:00:00 2001 From: filipw Date: Mon, 2 Dec 2019 16:09:00 +0100 Subject: [PATCH 5/5] updated changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 35cf9e274d..4515a91339 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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))