"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Why is < Escaped but > Remains Unescaped in Templates?

Why is < Escaped but > Remains Unescaped in Templates?

Published on 2024-11-18
Browse:900

Why is < Escaped but > Remains Unescaped in Templates? 
Remains Unescaped in Templates? " />

Escaping of in Templates

In the realm of file generation through templates, a perplexing issue has emerged: the unescaped > character, while its counterpart

html/template's automatic escaping mechanism, intended for HTML output, treats data values as plaintext that requires encoding for safe embedding. However, the rules of escaping are context-sensitive. In the given template, where the

The solution lies in aligning the template's purpose with the appropriate template engine:

  • If the output is HTML, use html/template, which provides context-sensitive escaping.
  • For non-HTML output, opt for text/template, which avoids unnecessary escaping, ensuring that are preserved in their original form.
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3