Skip to content

Commit 91ee3be

Browse files
zeripath6543techknowlogick
authored
Prevent incorrect HTML escaping in swagger.json (#14957)
* Prevent incorrect HTML escaping in swagger.json Fix #14706 Signed-off-by: Andrew Thornton <[email protected]> * oops add it to the helper Signed-off-by: Andrew Thornton <[email protected]> * try again Signed-off-by: Andrew Thornton <[email protected]> Co-authored-by: 6543 <[email protected]> Co-authored-by: techknowlogick <[email protected]>
1 parent df76d9f commit 91ee3be

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ GO_SOURCES_OWN := $(filter-out vendor/% %/bindata.go, $(GO_SOURCES))
127127
#To update swagger use: GO111MODULE=on go get -u github.com/go-swagger/go-swagger/cmd/swagger
128128
SWAGGER := $(GO) run -mod=vendor github.com/go-swagger/go-swagger/cmd/swagger
129129
SWAGGER_SPEC := templates/swagger/v1_json.tmpl
130-
SWAGGER_SPEC_S_TMPL := s|"basePath": *"/api/v1"|"basePath": "{{AppSubUrl}}/api/v1"|g
131-
SWAGGER_SPEC_S_JSON := s|"basePath": *"{{AppSubUrl}}/api/v1"|"basePath": "/api/v1"|g
130+
SWAGGER_SPEC_S_TMPL := s|"basePath": *"/api/v1"|"basePath": "{{AppSubUrl \| JSEscape \| Safe}}/api/v1"|g
131+
SWAGGER_SPEC_S_JSON := s|"basePath": *"{{AppSubUrl \| JSEscape \| Safe}}/api/v1"|"basePath": "/api/v1"|g
132132
SWAGGER_EXCLUDE := code.gitea.io/sdk
133133
SWAGGER_NEWLINE_COMMAND := -e '$$a\'
134134

modules/templates/helper.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ func NewFuncMap() []template.FuncMap {
9292
},
9393
"Safe": Safe,
9494
"SafeJS": SafeJS,
95+
"JSEscape": JSEscape,
9596
"Str2html": Str2html,
9697
"TimeSince": timeutil.TimeSince,
9798
"TimeSinceUnix": timeutil.TimeSinceUnix,
@@ -629,6 +630,11 @@ func Escape(raw string) string {
629630
return html.EscapeString(raw)
630631
}
631632

633+
// JSEscape escapes a JS string
634+
func JSEscape(raw string) string {
635+
return template.JSEscapeString(raw)
636+
}
637+
632638
// List traversings the list
633639
func List(l *list.List) chan interface{} {
634640
e := l.Front()

routers/api/v1/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//
1010
// Schemes: http, https
1111
// BasePath: /api/v1
12-
// Version: {{AppVer}}
12+
// Version: {{AppVer | JSEscape | Safe}}
1313
// License: MIT http://opensource.org/licenses/MIT
1414
//
1515
// Consumes:

templates/swagger/v1_json.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
"name": "MIT",
2020
"url": "http://opensource.org/licenses/MIT"
2121
},
22-
"version": "{{AppVer}}"
22+
"version": "{{AppVer | JSEscape | Safe}}"
2323
},
24-
"basePath": "{{AppSubUrl}}/api/v1",
24+
"basePath": "{{AppSubUrl | JSEscape | Safe}}/api/v1",
2525
"paths": {
2626
"/admin/cron": {
2727
"get": {

0 commit comments

Comments
 (0)