模板不必要地将 `<` 转义为 `<` 而不是 `>`
Template unnecessarily escaping `<` to `<` but not `>`
我在开发一个开发工具,该工具使用模板生成自述文件和许可证等文件。
除 <
字符的一个实例变成 <
之外,一切正常 - 相应的 >
字符正常工作并按预期出现在输出中。
模板文件:https://raw.githubusercontent.com/Southclaws/pawn-package-template/master/README.md 感兴趣的行是:
```pawn
#include <{{.Repo}}>
```
其中 Repo
被插入,预期结果为
#include <sometext>
但是实际出来的是:
#include <sometext>
我无法从文档中弄清楚为什么会发生这种情况。老实说,这似乎是一个错误,因为如果它正在寻找逃逸的东西,它肯定也会把 >
变成 >
,对吧?
html/template
提供自动的、上下文相关的转义以防止代码注入:
HTML templates treat data values as plain text which should be encoded so they can be safely embedded in an HTML document. The escaping is contextual, so actions can appear within JavaScript, CSS, and URI contexts.
html/template
只是生成HTML输出:
It provides the same interface as package text/template and should be used instead of text/template whenever the output is HTML.
如果输出不是 HTML,请改用 text/template
,它不会转义数据。
我在开发一个开发工具,该工具使用模板生成自述文件和许可证等文件。
除 <
字符的一个实例变成 <
之外,一切正常 - 相应的 >
字符正常工作并按预期出现在输出中。
模板文件:https://raw.githubusercontent.com/Southclaws/pawn-package-template/master/README.md 感兴趣的行是:
```pawn
#include <{{.Repo}}>
```
其中 Repo
被插入,预期结果为
#include <sometext>
但是实际出来的是:
#include <sometext>
我无法从文档中弄清楚为什么会发生这种情况。老实说,这似乎是一个错误,因为如果它正在寻找逃逸的东西,它肯定也会把 >
变成 >
,对吧?
html/template
提供自动的、上下文相关的转义以防止代码注入:
HTML templates treat data values as plain text which should be encoded so they can be safely embedded in an HTML document. The escaping is contextual, so actions can appear within JavaScript, CSS, and URI contexts.
html/template
只是生成HTML输出:
It provides the same interface as package text/template and should be used instead of text/template whenever the output is HTML.
如果输出不是 HTML,请改用 text/template
,它不会转义数据。