Skip to content

Commit

Permalink
fix: json checker
Browse files Browse the repository at this point in the history
  • Loading branch information
FGYFFFF committed Oct 10, 2024
1 parent 0e582ec commit 245df74
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
18 changes: 18 additions & 0 deletions cmd/hz/generator/json_checker_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package generator

import (
"regexp"
"testing"
)

var jsonCheck = regexp.MustCompile(`(?i:(application|text)/(json|.*\+json|json\-.*)(;\s*|$))`)

func Test_JSONChecker(t *testing.T) {
ct := []string{"application/json", "application/json;", "application/json; ", "application/json;charset=UTF-8", "application/json; charset=UTF-8"}

for _, c := range ct {
if jsonCheck.MatchString(c) != true {
t.Errorf("%s is json content-type, but get false", c)
}
}
}
4 changes: 2 additions & 2 deletions cmd/hz/generator/package_tpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ var (
jsonContentType = "application/json; charset=utf-8"
formContentType = "multipart/form-data"
jsonCheck = regexp.MustCompile(` + "`(?i:(application|text)/(json|.*\\+json|json\\-.*)(; |$))`)\n" +
`xmlCheck = regexp.MustCompile(` + "`(?i:(application|text)/(xml|.*\\+xml)(; |$))`)\n" +
jsonCheck = regexp.MustCompile(` + "`(?i:(application|text)/(json|.*\\+json|json\\-.*)(;\\s*|$))`)\n" +
`xmlCheck = regexp.MustCompile(` + "`(?i:(application|text)/(xml|.*\\+xml)(;\\s*|$))`)\n" +
`
)
Expand Down

0 comments on commit 245df74

Please sign in to comment.