Skip to content

Support indexed access to string characters - #1348

Open
alloutflo wants to merge 1 commit into
HubSpot:masterfrom
alloutflo:fix/633-string-indexing
Open

alloutflo wants to merge 1 commit into
HubSpot:masterfrom
alloutflo:fix/633-string-indexing

Conversation

@alloutflo

Copy link
Copy Markdown

Fixes #633.

With x = "stuff", {{ x[0] }} currently renders nothing and reports an unknown property, while {{ x[0:1] }} renders s. Add an internal string resolver before the bean resolver in both default resolver chains so indexed access returns the expected character as a String.

Support positive and negative integer indices, including numeric index strings. Empty strings, out-of-range indices, and integer overflow resolve to null. Preserve non-index property/method fallback, custom resolvers, and string immutability. Indexing follows the existing UTF-16 boundaries used by string slices and the length filter; other object types and SafeString handling are unchanged. No public API, configuration, or dependency changes.

Validation

  • Reproduced the original failure with a regression test on upstream 0eb936c before applying the fix.
  • Focused resolver, slicing, bean/map, and eager/deferred tests: 83 passed.
  • Full Maven verify with Temurin 17, 21, and 25: 2,254 tests per run, 0 failures/errors, 23 skipped. Maven runs on JDK 25 with the selected compiler/test toolchain; the 21/25 builds used fresh checkouts.
  • Spotless, Checkstyle, SpotBugs, and PMD passed; independent diff review and git diff --check found no issues.
  • Used JVM locale en_US. The existing FormatNumberFilterTest fails on untouched upstream under this Mac's de_AT locale and passes with en_US; no unrelated source changes were made.

Implemented with assistance from OpenAI Codex.

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

Successfully merging this pull request may close these issues.

Accessing a single string char at an index has no output

1 participant