Skip to content

Commit 245df74

Browse files
committed
fix: json checker
1 parent 0e582ec commit 245df74

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

cmd/hz/generator/json_checker_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package generator
2+
3+
import (
4+
"regexp"
5+
"testing"
6+
)
7+
8+
var jsonCheck = regexp.MustCompile(`(?i:(application|text)/(json|.*\+json|json\-.*)(;\s*|$))`)
9+
10+
func Test_JSONChecker(t *testing.T) {
11+
ct := []string{"application/json", "application/json;", "application/json; ", "application/json;charset=UTF-8", "application/json; charset=UTF-8"}
12+
13+
for _, c := range ct {
14+
if jsonCheck.MatchString(c) != true {
15+
t.Errorf("%s is json content-type, but get false", c)
16+
}
17+
}
18+
}

cmd/hz/generator/package_tpl.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,8 @@ var (
312312
jsonContentType = "application/json; charset=utf-8"
313313
formContentType = "multipart/form-data"
314314
315-
jsonCheck = regexp.MustCompile(` + "`(?i:(application|text)/(json|.*\\+json|json\\-.*)(; |$))`)\n" +
316-
`xmlCheck = regexp.MustCompile(` + "`(?i:(application|text)/(xml|.*\\+xml)(; |$))`)\n" +
315+
jsonCheck = regexp.MustCompile(` + "`(?i:(application|text)/(json|.*\\+json|json\\-.*)(;\\s*|$))`)\n" +
316+
`xmlCheck = regexp.MustCompile(` + "`(?i:(application|text)/(xml|.*\\+xml)(;\\s*|$))`)\n" +
317317
`
318318
)
319319

0 commit comments

Comments
 (0)