Skip to content

Commit d1d1d97

Browse files
authored
Merge pull request #23 from gofiber/codex/find-and-fix-a-bug
πŸ› fix: Default tag parsing
2 parents a460b99 + c087795 commit d1d1d97

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

β€Ž.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
unit:
1616
strategy:
1717
matrix:
18-
go-version: [1.22.x, 1.23.x]
18+
go-version: [1.22.x, 1.23.x, 1.24.x]
1919
platform: [ubuntu-latest, windows-latest, macos-latest, macos-13]
2020
runs-on: ${{ matrix.platform }}
2121
steps:
@@ -51,4 +51,4 @@ jobs:
5151
go-version: stable
5252

5353
- name: Test
54-
run: go run gotest.tools/gotestsum@latest -f testname -- ./... -race -count=15 -shuffle=on
54+
run: go run gotest.tools/gotestsum@latest -f testname -- ./... -race -count=15 -shuffle=on

β€Žcache.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,8 @@ func (o tagOptions) Contains(option string) bool {
310310
func (o tagOptions) getDefaultOptionValue() string {
311311
for _, s := range o {
312312
if strings.HasPrefix(s, "default:") {
313-
return strings.Split(s, ":")[1]
313+
return strings.SplitN(s, ":", 2)[1]
314314
}
315315
}
316-
317316
return ""
318317
}

β€Ždecoder_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2456,6 +2456,23 @@ func TestDefaultsAreNotSupportedForStructsAndStructSlices(t *testing.T) {
24562456
}
24572457
}
24582458

2459+
func TestDefaultValueWithColon(t *testing.T) {
2460+
t.Parallel()
2461+
type D struct {
2462+
URL string `schema:"url,default:http://localhost:8080"`
2463+
}
2464+
2465+
var d D
2466+
decoder := NewDecoder()
2467+
if err := decoder.Decode(&d, map[string][]string{}); err != nil {
2468+
t.Fatalf("unexpected error: %v", err)
2469+
}
2470+
2471+
if d.URL != "http://localhost:8080" {
2472+
t.Errorf("expected default url to be http://localhost:8080, got %s", d.URL)
2473+
}
2474+
}
2475+
24592476
func TestDecoder_MaxSize(t *testing.T) {
24602477
t.Parallel()
24612478

0 commit comments

Comments
Β (0)