On Apr 1, 2012 6:30 PM, "Vladimir Mihailenco" <vladimi...@gmail.com> wrote:
> Actually authors bothered to parse comments and strip them. So html/template already understands what comments are. Can html/template be changed to don't strip comments and treat them like ordinary HTML (which they are part of: http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.4)?
That would not be safe. html/template needs to know the proper context at each point of the template evaluation, but these types of comments cause their contents to be in a browser-dependent context, so the autoescaping can not be done reliably.
Are there other autoescaping template systems that preserve comments?
Dave.
That would not be safe. html/template needs to know the proper context at each point of the template evaluation, but these types of comments cause their contents to be in a browser-dependent context, so the autoescaping can not be done reliably.
Could you give an example of the comment that can not be properly autoescaped please?That would not be safe. html/template needs to know the proper context at each point of the template evaluation, but these types of comments cause their contents to be in a browser-dependent context, so the autoescaping can not be done reliably.
<p><!--[if lt IE 9]><script><![endif]-->{{.Stuff}}<!--[if lt IE 9]></script><![endif]--></p>
On Sun, Apr 1, 2012 at 7:17 AM, Vladimir Mihailenco <vladimi...@gmail.com> wrote:Could you give an example of the comment that can not be properly autoescaped please?That would not be safe. html/template needs to know the proper context at each point of the template evaluation, but these types of comments cause their contents to be in a browser-dependent context, so the autoescaping can not be done reliably.
<p><!--[if lt IE 9]><script><![endif]-->{{.Stuff}}<!--[if lt IE 9]></script><![endif]--></p>
You do realize that the template/html package does not escape HTML
that is of type html.HTML, right? Assuming your comments are coming
from something like {{ .HeaderMethod }}, just make HeaderMethod return
type html.HTML and return html.HTML("<!--comment-->") instead of just
"<!--comment-->"
On Monday, April 2, 2012 12:10:55 AM UTC+8, Kyle Lemons wrote:On Sun, Apr 1, 2012 at 7:17 AM, Vladimir Mihailenco <vladimi...@gmail.com> wrote:Could you give an example of the comment that can not be properly autoescaped please?That would not be safe. html/template needs to know the proper context at each point of the template evaluation, but these types of comments cause their contents to be in a browser-dependent context, so the autoescaping can not be done reliably.
<p><!--[if lt IE 9]><script><![endif]-->{{.Stuff}}<!--[if lt IE 9]></script><![endif]--></p>It's not the template's job to make assumptions about what I intend in this case --or even to try to be aware of the context in this case.Conditional comments should be preserved, else the template package would be unfit for many real world uses.
> I don't understand why you need conditional comments in dynamically-generated HTML. Look at the user-agent string, detect the browser version, and make your template generate the HTML that the particular browser needs.
You could be using it offline.
Also there is caching, yes
I don't understand why you need conditional comments in dynamically-generated HTML. Look at the user-agent string, detect the browser version, and make your template generate the HTML that the particular browser needs.
Identifying yourself as something.
> I compile different scripts per rendering engine, and one "general-purpose"
> one. If UA string is unlike any predefined patterns, I serve the general
> one. Further, the specific ones confirm that they are running on the right
> platform when they execute, and if not, they fallback to the general script.
>
> I've never seen any browsers "lie" about their user agent, what do you mean
> by this...
How would you ever possibly know? I have my browsers explicitly lie
about what UA they are so that I can log into a bank account that only
wants to allow IE. It is configurable, and people do configure it.
--dho
How would you ever possibly know?
I think we're talking about different things. I'm just talking about
the User-Agent header in the HTTP request. Javascript libraries will
always be able to tell what browser you're using based on what bugs
(errr, features) it implements on top of JS. In the case I provided,
the configuration is server-side and on the UA string.