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

Fix whitespace bug with dictionary support #128

Merged
merged 2 commits into from Jun 4, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions source/Handlebars/Compiler/Lexer/Parsers/WordParser.cs
Expand Up @@ -7,7 +7,7 @@ namespace HandlebarsDotNet.Compiler.Lexer
{
internal class WordParser : Parser
{
private const string validWordStartCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$.@";
private const string validWordStartCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$.@[]";

public override Token Parse(TextReader reader)
{
Expand Down Expand Up @@ -45,7 +45,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("[")))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is a safe assumption. We shouldn't merely check to see if the buffer contains a [, but we should check to see if the buffer contains a [ but has no subsequent ] to ensure we are inside the brackets.

{
break;
}
Expand All @@ -65,7 +65,8 @@ private string AccumulateWord(TextReader reader)

buffer.Append((char)node);
}
return buffer.ToString();

return buffer.ToString().Trim();
}
}
}
Expand Down