Skip to content

Provide thymeleaf templating #21

@de-jcup

Description

@de-jcup

Situation

{[#th:block th:with="sarifSupport=${new org.zaproxy.addon.reports.sarif.SarifReportDataSupport(reportData)}"]
   "runs": [
      {
         "results": [ [#th:block th:each="sarifResult, sarifResultState: ${sarifSupport.results}"]
...
[/th:block]],

shows an example for a thymeleaf template (see https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#textual-template-modes)

Unfortunately we have no outline here inside the editor and an error is shown because not valid JSON (what is correct).

Wanted

  • auto detect thymeleaf (when thymeleaf support is enabled in preferences)
  • no error marker
  • working outline

Solution

  • when it is a thyme leaf template, the parsed document shall not be the origin but - like in yaml editor for go templates - a tampered JSON document, where all thymeleaf parts are simply removed/replaced by spaces

Example1

[# th:each="message : ${messages}"]
                "message": {
                  "text": [[${sarifResult.message.text}]]
               },
[/]

will be replaced internally to


                "message": {
                  "text": []
               },

Example2

[#th:each="message : ${messages}"]
                "message": {
                  "level": "[(${sarifResult.level.value})]",
               },
[/th:each]

will be replaced internally to


                "message": {
                  "level": ""
               },

Detection howto

Everything starting with
[# marks a thymeleaf beginning tag, terminated by ]
[/ marks a thymeleaf end tag, terminated by ]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions