Repository: snowflakedb/gosnowflake
Pull request #1329 (2025-03-07 07:28:10)

SNOW-1964421 Fix PUT/GET regex
### Description

SNOW-1964421 Fix PUT/GET regex to handle whitespaces correctly.

### Checklist
- [x] Created tests which fail without the change (if possible)
- [x] Extended the README / documentation, if necessary


codecov[bot]: ## [Codecov](https://app.codecov.io/gh/snowflakedb/gosnowflake/pull/1329?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=snowflakedb) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 82.07%. Comparing base [(`f388736`)](https://app.codecov.io/gh/snowflakedb/gosnowflake/commit/f388736f51c028749591f073721f6c79dea57975?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=snowflakedb) to head [(`0009f39`)](https://app.codecov.io/gh/snowflakedb/gosnowflake/commit/0009f39740dced7ee155fad043176e91a7b35a61?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=snowflakedb).

<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff           @@
##           master    #1329   +/-   ##
=======================================
  Coverage   82.07%   82.07%           
=======================================
  Files          55       55           
  Lines       13722    13722           
=======================================
  Hits        11262    11262           
  Misses       2460     2460           
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/snowflakedb/gosnowflake/pull/1329?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=snowflakedb).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=snowflakedb).

<details><summary>🚀 New features to boost your workflow: </summary>

- ❄ [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
</details>

Patch:
diff --git a/file_transfer_agent.go b/file_transfer_agent.go
index 74d6ec8..4fe7d2c 100644
--- a/file_transfer_agent.go
+++ b/file_transfer_agent.go
@@ -44,8 +44,8 @@ const (
 	downloadCommand commandType = "DOWNLOAD"
 	unknownCommand  commandType = "UNKNOWN"
 
-	putRegexp string = `(?i)^(?:/\*.*\*/\s*)*put\s+`
-	getRegexp string = `(?i)^(?:/\*.*\*/\s*)*get\s+`
+	putRegexp string = `(?i)^(?:/\*.*\*/\s*)*\s*put\s+`
+	getRegexp string = `(?i)^(?:/\*.*\*/\s*)*\s*get\s+`
 )
 
 const (


Test patch:
diff --git a/file_transfer_agent_test.go b/file_transfer_agent_test.go
index 0b484fb..ebce706 100644
--- a/file_transfer_agent_test.go
+++ b/file_transfer_agent_test.go
@@ -13,6 +13,7 @@ import (
 	"os"
 	"path"
 	"path/filepath"
+	"regexp"
 	"strconv"
 	"strings"
 	"testing"
@@ -1004,3 +1005,59 @@ func testUploadDownloadOneFile(t *testing.T, isStream bool) {
 		t.Fatalf("failed to download file")
 	}
 }
+
+func TestPutGetRegexShouldIgnoreWhitespaceAtTheBeginning(t *testing.T) {
+	for _, test := range []struct {
+		regex string
+		query string
+	}{
+		{
+			regex: putRegexp,
+			query: "PUT abc",
+		},
+		{
+			regex: putRegexp,
+			query: "   PUT abc",
+		},
+		{
+			regex: putRegexp,
+			query: "\tPUT abc",
+		},
+		{
+			regex: putRegexp,
+			query: "\nPUT abc",
+		},
+		{
+			regex: putRegexp,
+			query: "\r\nPUT abc",
+		},
+		{
+			regex: getRegexp,
+			query: "GET abc",
+		},
+		{
+			regex: getRegexp,
+			query: "   GET abc",
+		},
+		{
+			regex: getRegexp,
+			query: "\tGET abc",
+		},
+		{
+			regex: getRegexp,
+			query: "\nGET abc",
+		},
+		{
+			regex: getRegexp,
+			query: "\r\nGET abc",
+		},
+	} {
+		{
+			t.Run(test.regex+" "+test.query, func(t *testing.T) {
+				regex := regexp.MustCompile(test.regex)
+				assertTrueE(t, regex.Match([]byte(test.query)))
+				assertFalseE(t, regex.Match([]byte("prefix "+test.query)))
+			})
+		}
+	}
+}