fix: allow Unicode letters as first character in identifiers (issue #416)#620
Merged
Conversation
) The WordParser's IsWord check previously only recognized ASCII letters and a fixed set of special characters as valid identifier start characters. Any Unicode letter (e.g. Japanese kanji like 姓) at the start of a Handlebars expression would fail with "Reached unparseable token in expression". The fix adds char.IsLetter(c) to the start-character check so any Unicode letter is accepted, matching the behaviour of Handlebars.js. Fixes #416 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #416
Summary
{{姓}}(and any template expression whose identifier starts with a non-ASCII Unicode letter) previously failed with"Reached unparseable token in expression: 姓}}".WordParser.IsWord()insource/Handlebars/Compiler/Lexer/Parsers/WordParser.cs: the check only accepted characters from a hard-coded ASCII set (ValidWordStartCharacters) and never fell through to accept Unicode letters.|| char.IsLetter(c)to the start-character check so any Unicode letter (as defined bySystem.Char) is a valid identifier start — matching Handlebars.js behaviour.AccumulateWordloop only stops on},~,),=, or whitespace), so{{a姓}}already worked — only the first character was broken.Changes
source/Handlebars/Compiler/Lexer/Parsers/WordParser.cs— one-line fix inIsWord()source/Handlebars.Test/IssueTests.cs— regression testIssue416_UnicodeFirstCharacterInIdentifierTest plan
Issue416_UnicodeFirstCharacterInIdentifierfails before the fix and passes after.🤖 Generated with Claude Code