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-1964421 Fix PUT/GET regex #1329

Merged
merged 2 commits into from
Mar 7, 2025
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
4 changes: 2 additions & 2 deletions file_transfer_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
57 changes: 57 additions & 0 deletions file_transfer_agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"os"
"path"
"path/filepath"
"regexp"
"strconv"
"strings"
"testing"
Expand Down Expand Up @@ -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)))
})
}
}
}