Child pages
  • [cms] The template meta comments are not validated [5.2.2-B1]
Skip to end of metadata
Go to start of metadata

Each template in the theme can have optional meta HTML comment, that is used to configure a category, that is created to match that template in the "Structure & Data" section. The typical comment looks like this:

<!--##
<NAME>Name of the page</NAME>
<DESC>Description of the page</DESC>
<SECTION>Top Category||Sub Category||Sub Sub Category</SECTION>
##-->

The following problems are known due way how processing of this comment is implemented:

  • no validation is made, that it's a valid XML (e.g. placing "&" instead of "&amp;" won't break anything
  • the XML is treated like a regular string and therefore typical XML errors (e.g. pair tag name mismatch) are simply ignored
  • when unknown XML settings are added developer isn't informed about that, which can lead to code working in unexpected ways

Solution

The plan below would allow separate all template comment related logic into one class and allow addition of new settings later if needed.

  1. create the "TemplateCommentParser" class, that: - 0.2h
    • would accept path to template as constructor argument
    • the "parse" method would return associative array of results
  2. add support for data types in the class: - 0.5h
    • "string" - any string
    • "boolean" - true (when "yes"), false (when "no"), exception otherwise
    • "integer" - as-as, when a positive integer, exception otherwise
    • "category_path" - would split value by "||" and trim each each element
  3. define supported settings and their data types as class properties (similar to "Fields" array in unit config with "type" and "default") - 0.3h
  4. when template doesn't exist throw an exception - 0.1h
  5. add "getDefaults" method, that will return an array (keys - field names, values - their default values) - 0.5h
  6. when no meta comment found, then return result of calling "getDefaults" method - 0.1h
  7. when meta comment found: - 0.3h
    • if it's one line long, then return an result of calling "getDefaults" method
    • if it's invalid XML, then throw an exception
    • when unsupported setting found, then throw an exception
    • when supported setting found, but it has value unknown format, then throw an exception
  8. return parsing result (if some fields not present, then add them with their default values)
  9. delete "kThemesHelper::parseTemplateMetaInfo" in favor of using "TemplateCommentParser::parse" method - 0.5h

Quote: 2.5h*1.4=3.5h

Related Discussions

Related Tasks

INP-1553 - Getting issue details... STATUS