adobe / htlengine

An HTL (Sightly) Interpreter/Compiler for Node.js
Apache License 2.0
47 stars 20 forks source link

@adobe/htlengine 6.x - variables are converted to lowercase and break #297

Closed jantimon closed 3 years ago

jantimon commented 3 years ago

Hi @tripodsan

I am only guessing that this is a bug in your code but I am not entirely sure.

Given the following template:

<template data-sly-template.headlineDemo="${@ textMessage}">
  <h1>${textMessage}!</h1>
</template>

the following code is generated:

  let headlineDemo;
  headlineDemo = function* _template_global_headlineDemo(args) { 
    let textMessage = args[1]['textMessage'] || '';
    let $t, $n = args[0];
    $.dom.text($n,"\n  ");
    $t = $.dom.create("h1",false,false);
    $n = $.dom.push($n,$t);
    const var_0 = yield $.xss(textmessage, "html");
    $.dom.append($n, var_0);
    $.dom.text($n,"!");
    $n = $.dom.pop($n);
    $.dom.text($n,"\n");
  };
  $.template('global', 'headlineDemo', headlineDemo);

On first glance this looks correct however there is something really strange:

the M in Message is uppercase in this line:

let textMessage = args[1]['textMessage'] || '';

but in this line it is lowercase:

const var_0 = yield $.xss(textmessage, "html");

Unfortunately node is case sensitive and will fail as it is not able to access textmessage

Do you have any idea what might cause this?

jantimon commented 3 years ago

Update: I tried with @adobe/htlengine@5 and it generates working code (no lowercasing):

let headlineDemo;
  headlineDemo = function* _template_global_headlineDemo(args) { 
    const textMessage = args[1]['textMessage'] || '';
    let $t, $n = args[0];
    $.dom.text($n,"\n  ");
    $t = $.dom.create("h1",false,false);
    $n = $.dom.push($n,$t);
    const var_0 = yield $.xss(textMessage, "html");
    $.dom.append($n, var_0);
    $.dom.text($n,"!");
    $n = $.dom.pop($n);
    $.dom.text($n,"\n");
  };
  $.template('global', 'headlineDemo', headlineDemo);
tripodsan commented 3 years ago

yes, this is a regression of the case-insensitivity fix. according to the HTL spec, all variables are case insensitive. I must have missed some edge cases. thanks for reporting.

github-actions[bot] commented 3 years ago

:tada: This issue has been resolved in version 6.3.3 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

jantimon commented 3 years ago

Thanks for the fix! :)