-
-
Notifications
You must be signed in to change notification settings - Fork 397
Closed
Labels
Description
Hello,
While using scriban, I can across a problem with ObjectToString where the escaping is incorrect.
Issue reproduction
var script = """[["a", "b"]] | array.each @(do; ret $0 | array.join("#"); end)""";
var context = new TemplateContext();
var result = Scriban.Template.Evaluate(script, context);
Console.WriteLine(context.ObjectToString(result));Actual output
["\"a\"#\"b\""]
Expected output
["a#b"]
I think it happens because context.ObjectToString is called inside array.join when evaluating so both the lazy evaluation and display logic is increasing _objectToStringLevel:
| var item = context.ObjectToString(obj); |
Proposed solution
Pass state as parameters to ObjectToString (defaults to 0) instead of using instance variables to avoid side-effects
scriban/src/Scriban/TemplateContext.Helpers.cs
Lines 80 to 81 in 63bc3d6
| private int _objectToStringLevel; | |
| private int _currentToStringLength; |