Home > Article > Backend Development > Why is < Escaped but > Remains Unescaped in Templates?
Remains Unescaped in Templates? " />
Escaping of < but Not > in Templates
In the realm of file generation through templates, a perplexing issue has emerged: the unescaped > character, while its counterpart < undergoes an inexplicable transformation into <. To unravel this mystery, we delve into the documentation.
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 < character appears within a #include directive, this escaping mechanism wrongly interprets it as HTML content and transforms it to <.
The solution lies in aligning the template's purpose with the appropriate template engine:
The above is the detailed content of Why is < Escaped but > Remains Unescaped in Templates?. For more information, please follow other related articles on the PHP Chinese website!