guigrpa / docx-templates

Template-based docx report creation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Template validation

daviatorstorm opened this issue · comments

Is it possible to make template validation before creating actual report?

The commands in the template are arbitrary JavaScript, so you cannot really validate them without executing the entire template. At least i havent found a convenient way to do so.

To validate user-created templates in my desktop app I just execute them and present any errors that occur to the user. Note that you should be aware of the security concerns related to untrusted/user-generated templates, but that's a different topic.

Maybe there is a way check template syntax?
I mean to check if commands

+++ QUERI { data { title, description }} +++
    ^^^^^
Error: Syntax error near 1:1. Unknown identifier "QUERI"

are written in the right way but skip values accessing

You can use listCommands to get a list of all the commands, but you'll have to parse and validate them using your own custom validation routine.

But still, the only 100% sure way to validate template correctness is by running the code in the template commands, that's the downside of allowing JavaScript in the templates.