Skip to content

Commit d9b5ae7

Browse files
authored
Decrease minimum character search name query parameter length to 2 for SA region (#32)
1 parent bb43da8 commit d9b5ae7

3 files changed

+35
-20
lines changed

handlers/getAdventurerSearch.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,22 @@ import (
1515
var profileSearchCache = cache.NewCache[[]models.Profile]()
1616

1717
func getAdventurerSearch(w http.ResponseWriter, r *http.Request) {
18-
page := validators.ValidatePageQueryParam(r.URL.Query()["page"])
19-
query, queryOk := validators.ValidateAdventurerNameQueryParam(r.URL.Query()["query"])
2018
region, regionOk := validators.ValidateRegionQueryParam(r.URL.Query()["region"])
21-
searchTypeQueryParam := r.URL.Query()["searchType"]
22-
searchType, searchTypeAsString := validators.ValidateSearchTypeQueryParam(searchTypeQueryParam)
19+
if !regionOk {
20+
giveBadRequestResponse(w)
21+
return
22+
}
2323

24-
if !queryOk || !regionOk {
24+
query, queryOk := validators.ValidateAdventurerNameQueryParam(r.URL.Query()["query"], region)
25+
if !queryOk {
2526
giveBadRequestResponse(w)
2627
return
2728
}
2829

30+
page := validators.ValidatePageQueryParam(r.URL.Query()["page"])
31+
searchTypeQueryParam := r.URL.Query()["searchType"]
32+
searchType, searchTypeAsString := validators.ValidateSearchTypeQueryParam(searchTypeQueryParam)
33+
2934
if ok := giveMaintenanceResponse(w, region); ok {
3035
return
3136
}

validators/ValidateAdventurerNameQueryParam.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,18 @@ import (
77

88
// The naming policies in BDO are fucked up
99
// This function only checks the length and allowed symbols
10-
func ValidateAdventurerNameQueryParam(query []string) (name string, ok bool) {
10+
func ValidateAdventurerNameQueryParam(query []string, region string) (name string, ok bool) {
1111
if 1 > len(query) {
1212
return "", false
1313
}
1414

15-
if len(query[0]) < 3 || len(query[0]) > 16 {
15+
minLength := map[string]int{
16+
"SA": 2,
17+
"NA": 3,
18+
"EU": 3,
19+
}[region]
20+
21+
if len(query[0]) < minLength || len(query[0]) > 16 {
1622
return query[0], false
1723
}
1824

validators/ValidateAdventurerNameQueryParam_test.go

+17-13
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,29 @@ func TestValidateAdventurerNameQueryParam(t *testing.T) {
77
expectedName string
88
expectedOk bool
99
input []string
10+
region string
1011
}{
11-
{input: []string{"1Number"}, expectedName: "1Number", expectedOk: true}, // Starts with a number
12-
{input: []string{"Adventurer_123"}, expectedName: "Adventurer_123", expectedOk: true},
13-
{input: []string{"JohnDoe"}, expectedName: "JohnDoe", expectedOk: true},
14-
{input: []string{"Name1", "Name2"}, expectedName: "Name1", expectedOk: true},
15-
{input: []string{"고대신"}, expectedName: "고대신", expectedOk: true}, // Adventurer name with Korean characters
12+
{input: []string{"1Number"}, region: "EU", expectedName: "1Number", expectedOk: true}, // Starts with a number
13+
{input: []string{"Adventurer_123"}, region: "EU", expectedName: "Adventurer_123", expectedOk: true},
14+
{input: []string{"JohnDoe"}, region: "EU", expectedName: "JohnDoe", expectedOk: true},
15+
{input: []string{"Name1", "Name2"}, region: "EU", expectedName: "Name1", expectedOk: true},
16+
{input: []string{"고대신"}, region: "EU", expectedName: "고대신", expectedOk: true}, // Adventurer name with Korean characters
1617

17-
{input: []string{""}, expectedName: "", expectedOk: false}, // Empty adventurer name
18-
{input: []string{"Ad"}, expectedName: "Ad", expectedOk: false}, // Too short
19-
{input: []string{"Adventurer With Spaces"}, expectedName: "Adventurer With Spaces", expectedOk: false}, // Contains spaces
20-
{input: []string{"AdventurerNameTooLong12345"}, expectedName: "AdventurerNameTooLong12345", expectedOk: false}, // Too long
21-
{input: []string{"Name$"}, expectedName: "Name$", expectedOk: false}, // Contains an invalid symbol
22-
{input: []string{}, expectedName: "", expectedOk: false},
18+
{input: []string{""}, region: "EU", expectedName: "", expectedOk: false}, // Empty adventurer name
19+
{input: []string{"Ad"}, region: "EU", expectedName: "Ad", expectedOk: false}, // Too short
20+
{input: []string{"Adventurer With Spaces"}, region: "EU", expectedName: "Adventurer With Spaces", expectedOk: false}, // Contains spaces
21+
{input: []string{"AdventurerNameTooLong12345"}, region: "EU", expectedName: "AdventurerNameTooLong12345", expectedOk: false}, // Too long
22+
{input: []string{"Name$"}, region: "EU", expectedName: "Name$", expectedOk: false}, // Contains an invalid symbol
23+
{input: []string{}, region: "EU", expectedName: "", expectedOk: false},
24+
25+
{input: []string{""}, region: "SA", expectedName: "", expectedOk: false},
26+
{input: []string{"Ad"}, region: "SA", expectedName: "Ad", expectedOk: true},
2327
}
2428

2529
for _, test := range tests {
26-
name, ok := ValidateAdventurerNameQueryParam(test.input)
30+
name, ok := ValidateAdventurerNameQueryParam(test.input, test.region)
2731
if name != test.expectedName || ok != test.expectedOk {
28-
t.Errorf("Input: %v, Expected: %v %v, Got: %v %v", test.input, test.expectedName, test.expectedOk, name, ok)
32+
t.Errorf("Input: %v %v, Expected: %v %v, Got: %v %v", test.input, test.region, test.expectedName, test.expectedOk, name, ok)
2933
}
3034
}
3135
}

0 commit comments

Comments
 (0)