Skip to content

Commit

Permalink
Prevent incorrect HTML escaping in swagger.json (go-gitea#14957)
Browse files Browse the repository at this point in the history
* Prevent incorrect HTML escaping in swagger.json

Fix go-gitea#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]>
  • Loading branch information
3 people authored Mar 12, 2021
1 parent df76d9f commit 91ee3be
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ GO_SOURCES_OWN := $(filter-out vendor/% %/bindata.go, $(GO_SOURCES))
#To update swagger use: GO111MODULE=on go get -u github.com/go-swagger/go-swagger/cmd/swagger
SWAGGER := $(GO) run -mod=vendor github.com/go-swagger/go-swagger/cmd/swagger
SWAGGER_SPEC := templates/swagger/v1_json.tmpl
SWAGGER_SPEC_S_TMPL := s|"basePath": *"/api/v1"|"basePath": "{{AppSubUrl}}/api/v1"|g
SWAGGER_SPEC_S_JSON := s|"basePath": *"{{AppSubUrl}}/api/v1"|"basePath": "/api/v1"|g
SWAGGER_SPEC_S_TMPL := s|"basePath": *"/api/v1"|"basePath": "{{AppSubUrl \| JSEscape \| Safe}}/api/v1"|g
SWAGGER_SPEC_S_JSON := s|"basePath": *"{{AppSubUrl \| JSEscape \| Safe}}/api/v1"|"basePath": "/api/v1"|g
SWAGGER_EXCLUDE := code.gitea.io/sdk
SWAGGER_NEWLINE_COMMAND := -e '$$a\'

Expand Down
6 changes: 6 additions & 0 deletions modules/templates/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func NewFuncMap() []template.FuncMap {
},
"Safe": Safe,
"SafeJS": SafeJS,
"JSEscape": JSEscape,
"Str2html": Str2html,
"TimeSince": timeutil.TimeSince,
"TimeSinceUnix": timeutil.TimeSinceUnix,
Expand Down Expand Up @@ -629,6 +630,11 @@ func Escape(raw string) string {
return html.EscapeString(raw)
}

// JSEscape escapes a JS string
func JSEscape(raw string) string {
return template.JSEscapeString(raw)
}

// List traversings the list
func List(l *list.List) chan interface{} {
e := l.Front()
Expand Down
2 changes: 1 addition & 1 deletion routers/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//
// Schemes: http, https
// BasePath: /api/v1
// Version: {{AppVer}}
// Version: {{AppVer | JSEscape | Safe}}
// License: MIT http://opensource.org/licenses/MIT
//
// Consumes:
Expand Down
4 changes: 2 additions & 2 deletions templates/swagger/v1_json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
"name": "MIT",
"url": "http://opensource.org/licenses/MIT"
},
"version": "{{AppVer}}"
"version": "{{AppVer | JSEscape | Safe}}"
},
"basePath": "{{AppSubUrl}}/api/v1",
"basePath": "{{AppSubUrl | JSEscape | Safe}}/api/v1",
"paths": {
"/admin/cron": {
"get": {
Expand Down

0 comments on commit 91ee3be

Please sign in to comment.