On Oct 28, 12:12 pm, Sam <
spull...@gmail.com> wrote:
> I would love to integrate this into the system, at the very least as
> an extension module. I can add a plugin API to the parser such that
> you will get a callback for each character and then when I need to
> encode I could call your system with the currently active encoding
> context. Have you made an attempt to integrate it into the parser? You
> can just fork the project on Github and I can help you do the work.
> Critically for performance reasons, the integration must be done at
> template compile time inside the MustacheBuilder's parser.
If you want a static approach, I would need to be able to get a
callback for each string of static text and a begin/end call for
sections.
For example, given the following template (and ignore whitespace)
Hello
{{#worlds}}
, {{world}}
{{/worlds}}!
I would like to see the following series of callbacks
safeText "Hello"
startSection
safeText ", "
interpolation
endSection
safeText "!"
When interpolation happens, I need to be able to do one of:
1. Specify a function that transforms the interpolated value to chars
to output
2. Specify a function that takes an interpolated value and a Writer/
Appendable to do the writing
3. Specify a function that takes a Writer/Appendable and wraps it so
that the resulting wrapper is used to write the interpolated value.
Option 2 would be ideal since I get access to the raw value, and it
leaves space for optimizing out buffer copies.
Ideally, when I see safeText, I would be able to substitute safe text.
For example, I would like to be able to normalize
safeText "<a href=
http://example.com/"
to
safeText "<a href=\"
http://example.com/"
A surprising number of attack vectors are closed when I can quote
unquoted attributes whose values include sections or interpolation
boundaries, and similarly if I can normalize '<' immediately before an
interpolation or section boundary.
> Though I believe that you can safely use the default encoding, I would
> love to be even resistant to misuse of the template engine.
The default encoding is plain text -> HTML text with entities?
I would also ideally get an event when a {{{expr}}} section is seen
that distinguishes it from a normal {{...}} section.
> Sam