Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template.Render throws InvalidCastException #122

Closed
Metalnem opened this issue Jan 21, 2019 · 1 comment
Closed

Template.Render throws InvalidCastException #122

Metalnem opened this issue Jan 21, 2019 · 1 comment
Labels

Comments

@Metalnem
Copy link

Template.Render can sometimes throw InvalidCastException when rendering template that doesn't have any errors (HasErrors property returns false). Here's the full program that reproduces this:

namespace Scriban.Run
{
  public class Program
  {
    public static void Main(string[] args)
    {
      var template = Template.ParseLiquid("{{html>0}}");
      template.Render(new { x = 0 });
    }
  }
}

And here's the full stack trace:

Exception has occurred: CLR/System.InvalidCastException
An unhandled exception of type 'System.InvalidCastException' occurred in System.Private.CoreLib.dll: 'Unable to cast object of type 'Scriban.Functions.HtmlFunctions' to type 'System.IConvertible'.'
   at System.Convert.ToInt32(Object value, IFormatProvider provider)
   at Scriban.TemplateContext.ToInt(SourceSpan span, Object value)
   at Scriban.TemplateContext.ToObject(SourceSpan span, Object value, Type destinationType)
   at Scriban.Syntax.ScriptBinaryExpression.CalculateOthers(TemplateContext context, SourceSpan span, ScriptBinaryOperator op, Object leftValue, Object rightValue)
   at Scriban.Syntax.ScriptBinaryExpression.Evaluate(TemplateContext context, SourceSpan span, ScriptBinaryOperator op, Object leftValue, Object rightValue)
   at Scriban.Syntax.ScriptBinaryExpression.Evaluate(TemplateContext context)
   at Scriban.TemplateContext.Evaluate(ScriptNode scriptNode, Boolean aliasReturnedFunction)
   at Scriban.Syntax.ScriptExpressionStatement.Evaluate(TemplateContext context)
   at Scriban.TemplateContext.Evaluate(ScriptNode scriptNode, Boolean aliasReturnedFunction)
   at Scriban.Syntax.ScriptBlockStatement.Evaluate(TemplateContext context)
   at Scriban.TemplateContext.Evaluate(ScriptNode scriptNode, Boolean aliasReturnedFunction)
   at Scriban.TemplateContext.Evaluate(ScriptNode scriptNode, Boolean aliasReturnedFunction)
   at Scriban.Template.EvaluateAndRender(TemplateContext context, Boolean render)
   at Scriban.Template.Render(TemplateContext context)
   at Scriban.Template.Render(Object model, MemberRenamerDelegate memberRenamer, MemberFilterDelegate memberFilter)

I'm using .NET Core 2.2 and the latest NuGet alpha version of Scriban (2.0.0-alpha-005).

Found via SharpFuzz.

@xoofx
Copy link
Member

xoofx commented Mar 10, 2019

Fixed in 2.0.0+

@xoofx xoofx closed this as completed Mar 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants