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

SNOW-1545648: Fix PUT command error if file path contains spaces and single quotes #1066

Merged
merged 16 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 6 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
17 changes: 16 additions & 1 deletion Snowflake.Data.Tests/UnitTests/SFFileTransferAgentTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright (c) 2012-2023 Snowflake Computing Inc. All rights reserved.
*/

Expand Down Expand Up @@ -69,6 +69,10 @@ class SFFileTransferAgentTest : SFBaseTest
// Mock file content
const string FileContent = "FTAFileContent";

// Mock file paths
const string FilePathWithoutSpaces = "C:/Users/Test/folder_without_space/*.*";
const string FilePathWithSpaces = "C:/Users/Test/folder with space/*.*";
sfc-gh-knozderko marked this conversation as resolved.
Show resolved Hide resolved

[SetUp]
public void BeforeEachTest()
{
Expand Down Expand Up @@ -634,5 +638,16 @@ public void TestDownloadThrowsErrorDirectoryNotFound()
Assert.IsInstanceOf<DirectoryNotFoundException>(innerException);
Assert.That(innerException?.Message, Does.Match("Could not find a part of the path .*"));
}

[Test]
[TestCase("PUT file://" + FilePathWithoutSpaces + " @TestStage", FilePathWithoutSpaces)]
[TestCase("PUT file://" + FilePathWithSpaces + " @TestStage", FilePathWithSpaces)]
[TestCase("PUT 'file://" + FilePathWithoutSpaces + "' @TestStage", FilePathWithoutSpaces)]
[TestCase("PUT 'file://" + FilePathWithSpaces + "' @TestStage", FilePathWithSpaces)]
public void TestGetFilePathFromPutCommand(string query, string expectedFilePath)
{
var actualFilePath = SFFileTransferAgent.getFilePathFromPutCommand(query);
Assert.AreEqual(expectedFilePath, actualFilePath);
}
}
sfc-gh-knozderko marked this conversation as resolved.
Show resolved Hide resolved
}
10 changes: 8 additions & 2 deletions Snowflake.Data/Core/FileTransfer/SFFileTransferAgent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright (c) 2021 Snowflake Computing Inc. All rights reserved.
*/

Expand Down Expand Up @@ -527,13 +527,19 @@ internal async Task updatePresignedUrlAsync(CancellationToken cancellationToken)
/// </summary>
/// <param name="query">The query containing the file path</param>
/// <returns>The file path contained by the query</returns>
private string getFilePathFromPutCommand(string query)
internal static string getFilePathFromPutCommand(string query)
{
sfc-gh-knozderko marked this conversation as resolved.
Show resolved Hide resolved
// Extract file path from PUT command:
// E.g. "PUT file://C:<path-to-file> @DB.SCHEMA.%TABLE;"
int startIndex = query.IndexOf("file://") + "file://".Length;
int endIndex = query.Substring(startIndex).IndexOf('@') - 1;
string filePath = query.Substring(startIndex, endIndex);

// Check if file path contains an enclosing (') char
if (filePath[filePath.Length - 1] == '\'')
{
filePath = filePath.Substring(0, filePath.Length - 1);
}
return filePath;
}

Expand Down
Loading