Skip to content

Commit 66c0f63

Browse files
committed
Former-commit-id: 2b8dfec7d43298bc9ace94595359867180634f04
1 parent 1977897 commit 66c0f63

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require (
1818
github.com/iris-contrib/go.uuid v2.0.0+incompatible
1919
github.com/iris-contrib/pongo2 v0.0.1
2020
github.com/iris-contrib/schema v0.0.1
21-
github.com/iris-contrib/jade v1.1.1
21+
github.com/iris-contrib/jade v1.1.2
2222
github.com/json-iterator/go v1.1.9
2323
github.com/kataras/golog v0.0.10
2424
github.com/kataras/neffos v0.0.14

view/pug.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"io/ioutil"
66
"path"
7+
"strings"
78

89
"github.com/iris-contrib/jade"
910
)
@@ -22,28 +23,34 @@ import (
2223
// https://github.com/kataras/iris/tree/master/_examples/view/template_pug_3
2324
func Pug(directory, extension string) *HTMLEngine {
2425
s := HTML(directory, extension)
26+
2527
s.middleware = func(name string, text []byte) (contents string, err error) {
28+
name = path.Join(path.Clean(directory), name)
2629
tmpl := jade.New(name)
27-
// Fixes: https://github.com/kataras/iris/issues/1450
28-
// by adding a custom ReadFunc inside the jade parser.
29-
// And Also able to use relative paths on "extends" and "include" directives:
30-
// e.g. instead of extends "templates/layout.pug" we use "layout.pug"
31-
// so contents of templates are independent of their root location.
3230
tmpl.ReadFunc = func(name string) ([]byte, error) {
33-
name = path.Join(directory, name)
31+
if !strings.HasPrefix(path.Clean(name), path.Clean(directory)) {
32+
name = path.Join(directory, name)
33+
}
34+
3435
if s.assetFn != nil {
3536
return s.assetFn(name)
3637
}
3738
return ioutil.ReadFile(name)
3839
}
3940

40-
tmpl, err = tmpl.Parse(text)
41+
// Fixes: https://github.com/kataras/iris/issues/1450
42+
// by adding a custom ReadFunc inside the jade parser.
43+
// And Also able to use relative paths on "extends" and "include" directives:
44+
// e.g. instead of extends "templates/layout.pug" we use "layout.pug"
45+
// so contents of templates are independent of their root location.
46+
47+
exec, err := tmpl.Parse(text)
4148
if err != nil {
4249
return
4350
}
4451

4552
b := new(bytes.Buffer)
46-
tmpl.WriteIn(b)
53+
exec.WriteIn(b)
4754
return b.String(), nil
4855
}
4956
return s

0 commit comments

Comments
 (0)