suspecion of bug in fcl-mustache package.
lazarus / 21-General
----------------------------------------------------------------------
BSaidus · 2023-04-15 15:17
Helo.
While trying to generate .html page based on template where expression
exists, I experiment a strange error in debug mode and nothing happen
in release.
given this :
json data:
Code: Text [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i {
"host":{ "name" : "uc1.uccenos.net", "ip" :
"123.33.32.1", "mask" : 24, "gateway" : "123.33.23.3" }}
html template:
Code: Text [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i
hos
tnam:{{host.name}}
ip:{{host.ip}}
mask:{{host.mask}}
li>
gateway:{{host.gateway}}
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i procedure
TForm1.FormCreate(Sender: TObject);begin //fpMus :=
TMustache.Create(Self); fpMusEx := TMustacheExpr.Create(Self);
//fpMusEx.; //fExpr := TFPExpressionParser.Create(Self);
//fpMusEx.ExpressionParser := fExpr;
fpMusEx.ExpressionParser.BuiltIns := AllBuiltIns;
fpMusEx.RegisterVariables(mmJson.Text, 'host'); end; procedure
TForm1.Button1Click(Sender: TObject);begin { CASE 1 }
fpMusEx.Template := mmTemp.Text; mmRes.Text :=
fpMusEx.Render(mmJson.Text); { CASE 2 } //mmRes.Append(
fpMusEx.Render(mmTemp.Text, mmJson.Text) ); //mmRes.Text :=
fpMusEx.Render(mmTemp.Text, mmJson.Text);end;
I've tried many combinaison for the template but it do not work in
realease mode and error occurence in debug mode.
Attached a simple program to reproduce.
see: https://forum.lazarus.freepascal.org/index.php/topic,63007.msg477
188.html#msg477188
----------------------------------------------------------------------
bobby100 · 2023-04-15 17:16
It seems that your variable I takes a value greater than the length of
aTemplate array.
----------------------------------------------------------------------
BSaidus · 2023-04-15 17:27
Quote from: bobby100 on April 15, 2023, 07:16:43 pmIt seems that your
variable I takes a value greater than the length of aTemplate array.
This I belongs to then fpmustache.pas which belong to the fcl-mustache
package.
----------------------------------------------------------------------
Leledumbo · 2023-04-15 20:29
Bugtracker link is on the top left, it won't be seen here in the
forum.