mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
fix issue #1611
This commit is contained in:
@ -13,10 +13,12 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/v2/debug/gdebug"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
"github.com/gogf/gf/v2/os/genv"
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"github.com/gogf/gf/v2/util/guid"
|
||||
)
|
||||
|
||||
@ -74,3 +76,27 @@ func Test_XUrlPath(t *testing.T) {
|
||||
t.Assert(c.GetContent(ctx, "/test1"), "test2")
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Issue1611(t *testing.T) {
|
||||
s := g.Server(guid.S())
|
||||
v := g.View(guid.S())
|
||||
content := "This is header"
|
||||
gtest.AssertNil(v.SetPath(gdebug.TestDataPath("issue1611")))
|
||||
s.SetView(v)
|
||||
s.BindHandler("/", func(r *ghttp.Request) {
|
||||
gtest.AssertNil(r.Response.WriteTpl("index/layout.html", g.Map{
|
||||
"header": content,
|
||||
}))
|
||||
})
|
||||
s.SetDumpRouterMap(false)
|
||||
s.Start()
|
||||
defer s.Shutdown()
|
||||
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
c := g.Client()
|
||||
c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
|
||||
|
||||
t.Assert(gstr.Contains(c.GetContent(ctx, "/"), content), true)
|
||||
})
|
||||
}
|
||||
|
||||
3
net/ghttp/testdata/issue1611/header.html
vendored
Normal file
3
net/ghttp/testdata/issue1611/header.html
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{{define "header"}}
|
||||
<h1>{{.header}}</h1>
|
||||
{{end}}
|
||||
9
net/ghttp/testdata/issue1611/index/layout.html
vendored
Normal file
9
net/ghttp/testdata/issue1611/index/layout.html
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>GoFrame Layout</title>
|
||||
</head>
|
||||
<body>
|
||||
{{template "header" .}}
|
||||
</body>
|
||||
</html>
|
||||
@ -364,7 +364,7 @@ func (view *View) searchFile(ctx context.Context, file string) (path string, fol
|
||||
`\/`,
|
||||
)
|
||||
if path, _ = gspath.Search(searchPath, relativePath); path != "" {
|
||||
folder = gfile.Dir(path)
|
||||
folder = gfile.Join(searchPath, tryFolder)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user