From 48265e1947b47895a8bc3d616cf8d669f3effe09 Mon Sep 17 00:00:00 2001 From: Manfred Touron Date: Thu, 13 Sep 2018 17:28:14 +0200 Subject: [PATCH] feat: support escaped paths (#107) --- encoder.go | 10 ++++++++++ .../%7B%7B.File.Package%7D%7D_grpc_js.js.tmpl} | 0 .../service.go.tmpl | 0 3 files changed, 10 insertions(+) rename examples/flow/templates/{{{.File.Package}}/{{.File.Package}}_grpc_js.js.tmpl => %7B%7B.File.Package%7D%7D/%7B%7B.File.Package%7D%7D_grpc_js.js.tmpl} (100%) rename examples/single-package-mode/templates/{{{.File.Name|dir}} => %7B%7B.File.Name%7Cdir%7D%7D}/service.go.tmpl (100%) diff --git a/encoder.go b/encoder.go index 8258b3b..2be60b8 100644 --- a/encoder.go +++ b/encoder.go @@ -3,6 +3,7 @@ package main import ( "bytes" "log" + "net/url" "os" "path/filepath" "strings" @@ -94,6 +95,7 @@ func (e *GenericTemplateBasedEncoder) templates() ([]string, error) { if e.debug { log.Printf("new template: %q", rel) } + filenames = append(filenames, rel) return nil }) @@ -135,6 +137,14 @@ func (e *GenericTemplateBasedEncoder) genAst(templateFilename string) (*Ast, err Enum: e.enum, } buffer := new(bytes.Buffer) + + unescaped, err := url.QueryUnescape(templateFilename) + if err != nil { + log.Printf("failed to unescape filepath %q: %v", templateFilename, err) + } else { + templateFilename = unescaped + } + tmpl, err := template.New("").Funcs(pgghelpers.ProtoHelpersFuncMap).Parse(templateFilename) if err != nil { return nil, err diff --git a/examples/flow/templates/{{.File.Package}}/{{.File.Package}}_grpc_js.js.tmpl b/examples/flow/templates/%7B%7B.File.Package%7D%7D/%7B%7B.File.Package%7D%7D_grpc_js.js.tmpl similarity index 100% rename from examples/flow/templates/{{.File.Package}}/{{.File.Package}}_grpc_js.js.tmpl rename to examples/flow/templates/%7B%7B.File.Package%7D%7D/%7B%7B.File.Package%7D%7D_grpc_js.js.tmpl diff --git a/examples/single-package-mode/templates/{{.File.Name|dir}}/service.go.tmpl b/examples/single-package-mode/templates/%7B%7B.File.Name%7Cdir%7D%7D/service.go.tmpl similarity index 100% rename from examples/single-package-mode/templates/{{.File.Name|dir}}/service.go.tmpl rename to examples/single-package-mode/templates/%7B%7B.File.Name%7Cdir%7D%7D/service.go.tmpl