Skip to content
  • Andrew Lyons's avatar
    MDL-52136 core: Add support for quoting variables in mustache helpers · 0b4bff8c
    Andrew Lyons authored
    This is required for when helpers include json-encoded variables as arguments.
    As an example, imagine a template with content:
    
    {{# str }} somekey, someidentifier, { "fullname": "{{ fullname }}" } {{/ str }}
    
    If the fullname variable were to include the double-quote character (e.g.
    John "Trevor" Doe) because of the way in which mustache renders content, it
    would become:
    
    {{# str }} somekey, someidentifier, { "fullname": "John "Trevor" Doe" } {{/ str }}
    
    This results in an invalid JSON structure.
    
    To work around this issue, the quote characters in the passed variable
    must be escaped:
    
    {{# str }} somekey, someidentifier, { "fullname": "John \"Trevor\" Doe" } {{/ str }}
    
    Unfortunately, Mustache provides no way of doing so natively.
    
    With this function, we can quote the text as appropriate:
    
    {{# str }} somekey, someidentifier, { "fullname": {{# quote }}{{ fullname }}{{/ quote }} } {{/ str }}
    
    This also handles the case where the quoted cont...
    0b4bff8c