diff --git a/source/Handlebars/Compiler/Lexer/Parsers/WordParser.cs b/source/Handlebars/Compiler/Lexer/Parsers/WordParser.cs index ac24c4ac..d715b72d 100644 --- a/source/Handlebars/Compiler/Lexer/Parsers/WordParser.cs +++ b/source/Handlebars/Compiler/Lexer/Parsers/WordParser.cs @@ -1,13 +1,12 @@ using System; using System.IO; -using System.Linq; using System.Text; namespace HandlebarsDotNet.Compiler.Lexer { internal class WordParser : Parser { - private const string validWordStartCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$.@"; + private const string validWordStartCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$.@[]"; public override Token Parse(TextReader reader) { @@ -45,7 +44,7 @@ private string AccumulateWord(TextReader reader) { var peek = (char)reader.Peek(); - if (peek == '}' || peek == '~' || peek == ')' || char.IsWhiteSpace(peek)) + if (peek == '}' || peek == '~' || peek == ')' || (char.IsWhiteSpace(peek) && !buffer.ToString().Contains("["))) { break; } @@ -65,7 +64,13 @@ private string AccumulateWord(TextReader reader) buffer.Append((char)node); } - return buffer.ToString(); + + if (buffer.ToString().Contains("[") && !buffer.ToString().Contains("]")) + { + throw new HandlebarsCompilerException("Expression is missing a closing ]."); + } + + return buffer.ToString().Trim(); } } }