Escape file URIs (#1189)

* Escape file URIs

* Fix test

* Add tests
This commit is contained in:
Charles Gagnon
2021-04-16 15:33:11 -07:00
committed by GitHub
parent 6fe715d2d8
commit dc6555a823
5 changed files with 37 additions and 12 deletions

View File

@@ -18,11 +18,13 @@ using Microsoft.SqlTools.ServiceLayer.Test.Common;
using Microsoft.SqlTools.ServiceLayer.Test.Common.RequestContextMocking;
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
using Microsoft.SqlTools.ServiceLayer.Workspace;
using Moq;
using NUnit.Framework;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
{
public class InvalidParams : ExecuteRequestParamsBase { }
public class ServiceIntegrationTests
{
@@ -131,12 +133,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
// ... Mock up an implementation of ExecuteRequestParamsBase
// ... Create a query execution service without a connection service or workspace
// service (we won't execute code that uses either
var mockParams = new Mock<ExecuteRequestParamsBase>().Object;
var invalidParams = new InvalidParams() { OwnerUri = "" };
var queryService = new QueryExecutionService(null, null);
// If: I attempt to get query text from the mock params
// Then: It should throw an exception
Assert.Throws<InvalidCastException>(() => queryService.GetSqlText(mockParams));
Assert.Throws<InvalidCastException>(() => queryService.GetSqlText(invalidParams));
}
#endregion

View File

@@ -198,22 +198,28 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Workspace
}
[Test]
public async Task WorkspaceContainsFile()
[TestCase(TestObjects.ScriptUri)]
[TestCase("file://some/path%20with%20encoded%20spaces/file.sql")]
[TestCase("file://some/path with spaces/file.sql")]
[TestCase("file://some/fileWith#.sql")]
[TestCase("file://some/fileUriWithQuery.sql?var=foo")]
[TestCase("file://some/fileUriWithFragment.sql#foo")]
public async Task WorkspaceContainsFile(string uri)
{
var workspace = new ServiceLayer.Workspace.Workspace();
var workspaceService = new WorkspaceService<SqlToolsSettings> {Workspace = workspace};
var openedFile = workspace.GetFileBuffer(TestObjects.ScriptUri, string.Empty);
workspace.GetFileBuffer(uri, string.Empty);
// send a document open event
var openParams = new DidOpenTextDocumentNotification
{
TextDocument = new TextDocumentItem { Uri = TestObjects.ScriptUri }
TextDocument = new TextDocumentItem { Uri = uri }
};
await workspaceService.HandleDidOpenTextDocumentNotification(openParams, eventContext: null);
// verify the file is being tracked by workspace
Assert.True(workspaceService.Workspace.ContainsFile(TestObjects.ScriptUri));
Assert.True(workspaceService.Workspace.ContainsFile(uri));
}
[Test]