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 engine throws some unexpected exceptions #282

Closed
Metalnem opened this issue Jan 23, 2019 · 0 comments
Closed

Template engine throws some unexpected exceptions #282

Metalnem opened this issue Jan 23, 2019 · 0 comments

Comments

@Metalnem
Copy link

Template engine can throw many unexpected exceptions when compiling or rendering templates (I assume that the expected exception type is HandlebarsException). Here are the types of exceptions it can throw, the code snippets used to trigger them, and the stack traces:

ArgumentException

HandlebarsDotNet.Handlebars.Compile("{{p=\np=}}")(new object());
Exception has occurred: CLR/System.ArgumentException
An unhandled exception of type 'System.ArgumentException' occurred in System.Private.CoreLib.dll: 'An item with the same key has already been added. Key: p'
   at System.ThrowHelper.ThrowAddingDuplicateWithKeyArgumentException[T](T key)
   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at HandlebarsDotNet.Compiler.HashParametersConverter.AccumulateParameters(IEnumerator`1 enumerator)
   at HandlebarsDotNet.Compiler.HashParametersConverter.<ConvertTokens>d__2.MoveNext()
   at System.Collections.Generic.List`1.AddEnumerable(IEnumerable`1 enumerable)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at HandlebarsDotNet.Compiler.ExpressionBuilder.ConvertTokensToExpressions(IEnumerable`1 tokens)
   at HandlebarsDotNet.Compiler.HandlebarsCompiler.Compile(TextReader source)
   at HandlebarsDotNet.Handlebars.HandlebarsEnvironment.Compile(String template)

InvalidCastException

HandlebarsDotNet.Handlebars.Compile("{{>r=}}")(new object());
Unhandled Exception: System.InvalidCastException: Unable to cast object of type 'HandlebarsDotNet.Compiler.HashParameterDictionary' to type 'System.String'.
   at lambda_method(Closure , TextWriter , Object )
   at HandlebarsDotNet.Handlebars.HandlebarsEnvironment.<>c__DisplayClass7_0.<Compile>b__0(Object context)

InvalidOperationException

HandlebarsDotNet.Handlebars.Compile("{{0")(new object());
Exception has occurred: CLR/System.InvalidOperationException
An unhandled exception of type 'System.InvalidOperationException' occurred in Handlebars.dll: 'Reached end of template before the expression was closed.'
   at HandlebarsDotNet.Compiler.Lexer.LiteralParser.AccumulateLiteral(TextReader reader, Boolean captureDelimiter, Char[] delimiters)
   at HandlebarsDotNet.Compiler.Lexer.LiteralParser.Parse(TextReader reader)
   at HandlebarsDotNet.Compiler.Lexer.Tokenizer.<Parse>d__8.MoveNext()
   at System.Collections.Generic.List`1.AddEnumerable(IEnumerable`1 enumerable)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at HandlebarsDotNet.Compiler.HandlebarsCompiler.Compile(TextReader source)
   at HandlebarsDotNet.Handlebars.HandlebarsEnvironment.Compile(String template)

NullReferenceException

HandlebarsDotNet.Handlebars.Compile("{{@..}}")(new object());
Exception has occurred: CLR/System.NullReferenceException
An unhandled exception of type 'System.NullReferenceException' occurred in Handlebars.dll: 'Object reference not set to an instance of an object.'
   at HandlebarsDotNet.Compiler.PathBinder.ResolvePath(BindingContext context, String path)
   at HandlebarsDotNet.Handlebars.HandlebarsEnvironment.<>c__DisplayClass7_0.<Compile>b__0(Object context)

Found via SharpFuzz.

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

No branches or pull requests

2 participants