代码是这样的:
输出是这样的:
https 后面的 //被截没了?
我之前见过这个标准库过滤<!---->
的注释,这 js 里的注释也会处理掉?还处理错了位置?
我肯定是跟这个库有什么误会。。。
又做了一些测试
isComment
函数可以使返回结果正常简化后的代码
//Go 1.14 amd64 win10 package main import ( "github.com/gin-gonic/gin" "net/http" ) func main() { r := gin.Default() r.Static("/assets", "./assets") r.LoadHTMLGlob("tmpl/*") r.GET("/test", func(ctx *gin.Context) { ctx.HTML(http.StatusOK, "test.tmpl", map[string]interface{}{}) }) if err := r.Run(); err != nil { panic(err) } }
<!-- test.tmpl --> <!doctype html> <html lang="zh-cn"> <head> {{template "head"}} </head> <body> {{template "foot"}} </body> </html> <!-- base.tmpl --> {{define "head"}} <meta charset="UTF-8"> <!-- bulabula... --> {{end}} {{define "foot"}} <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script> <script type="text/Javascript" src="http://www.v2ex.com//js.users.51.la/00000.js"></script> <script> if ($("#Client-IP").length > 0) { $.ajax({ url: "https://myip.ipip.net/", success: function (result) {} ); $.ajax({ url: "https://api.ip.sb/geoip", # 这里就是图片哪里被吃的地方 success: function (result) {} }); } </script> {{end}}
![]() | 1 Reficul 2020-03-08 21:53:33 +08:00 发个最小 Demo 的 Code 上来看看? |
2 thefack 2020-03-08 21:56:27 +08:00 有点想笑。。 |
![]() | 3 tealover007 2020-03-08 22:21:22 +08:00 试着\/\/转一下? |
![]() | 4 CEBBCAT 2020-03-08 22:22:10 +08:00 via Android 按理说不应该的,上个 demo+1 |
![]() | 5 Mohanson 2020-03-08 22:26:54 +08:00 ![]() 我的经验是, 当怀疑语言本身 /标准库 /操作系统 /计算机有 BUG 的时候, 99.9% 是自己的代码有 BUG... |
![]() | 6 loading 2020-03-08 22:27:05 +08:00 via Android 为啥要在 html 里直接写 js。 html 和 js 视乎是分开处理。 |
![]() | 7 Yoock 2020-03-08 22:30:21 +08:00 字符串转义 |
![]() | 8 reus 2020-03-08 23:28:11 +08:00 ![]() |
![]() | 9 reus 2020-03-08 23:38:07 +08:00 不过字符串外面的注释确实会过滤掉,可能旧版本有 bug 也不奇怪,升级到 1.14 试试 |
![]() | 10 zhshch OP @Reficul #1 @CEBBCAT #4 Code 上了 @tealover007 #3 输出结果变成 https:\/\/api.ip.sb/geoip 也不是预期 @loading #6 确实昨晚上分成两个文件规避了,但是这个现象依旧很困惑 |
![]() | 11 Vegetable 2020-03-09 10:06:25 +08:00 你给出的 demo 无法复现 |
12 BlackBerry999 2020-03-09 11:23:11 +08:00 url 编码一下 |
![]() | 13 palytoxin 2020-03-09 14:42:29 +08:00 via iPhone 你引入的 cdn 有没有被修改掉? |
![]() | 14 Reficul 2020-03-11 10:29:57 +08:00 直接调用 html/template 无法复现 |
15 noisywolf 2020-03-11 12:22:32 +08:00 你给出的 demo 无法复现 |