fix: case-sensitive resolution of same-spelling variables (issue #434)#629
Merged
Conversation
When multiple variables share the same spelling but differ only in case
(e.g. TEST vs test), the helpers dictionary's case-insensitive lookup
could return a LateBindHelperDescriptor cached for a differently-cased
path. This caused {{test}} to resolve to the value of TEST. Fix detects
this mismatch in PathBinder and creates a fresh LateBindHelperDescriptor
carrying the exact casing of the current expression.
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 #434
When multiple variables share the same spelling but differ in case (e.g.
TESTvstest), each now resolves to its own correctly-cased property.Root cause
configuration.Helpersuses aFixedSizeDictionarywith aPathInfoLightEqualityComparerthat compares keys case-insensitively. When{{TEST}}is compiled first, aLateBindHelperDescriptorkeyed toTESTis stored. When{{test}}is compiled next,TryGetValuefinds theTESTentry (same bucket), and the cached descriptor — which resolvesTESTat runtime — is reused unchanged. So both expressions resolve the sameTESTproperty.Fix
In
PathBinder.VisitPathExpression, after a successfulTryGetValue, check whether the found entry is aLateBindHelperDescriptorwhose storedName.Pathdiffers (by ordinal) from the currentpathInfo.Path. If so, create a newLateBindHelperDescriptorwith the correct case. The new descriptor is used for this expression only (not re-stored in the dictionary, since the case-insensitive slot is already occupied).Test plan
Issue434_CaseSensitiveLookupWithSameSpellingVariablesinsource/Handlebars.Test/Issues/Issue434Tests.cs— confirmed red before fix, green after🤖 Generated with Claude Code