Skip to content

Find a whole JSON string before a substring in FindLocation [patch] - #63

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/33-findlocation-whole-strings
Nov 4, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/33-findlocation-whole-strings

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

MetadataFile.FindLocation(needle) and FindLocation(anchor, needle) found both strings with a plain ordinal IndexOf, so a name contained in a longer one matched the longer one. With SquareMeter listed before Meter, both overloads pointed at the SquareMeter entry.

Both overloads now look for the quoted string ("Meter") first and return a span that covers only the name inside the quotes. The raw substring search remains the fallback, so a number, or an anchor the caller has already quoted (as the existing "\"b\"" test does), is still found.

Tests:

  • FindLocationSkipsALongerNameThatContainsTheNeedle and ScopedFindLocationSkipsALongerNameThatContainsTheAnchor use the repro from the issue. Both fail on main (they land on line 2) and pass with the change.
  • FindLocationStillFindsTextThatIsNotAWholeString covers the fallback.
  • The full suite passes: 69 of 69.

Fixes #33


Generated by Claude Code

FindLocation(needle) and FindLocation(anchor, needle) matched with a plain
substring search, so "Meter" landed inside "SquareMeter" and the anchored
overload scoped to the wrong entry. Both now look for the quoted string
first and fall back to the raw search only when that finds nothing.

Fixes #33

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW4i7FzmxvaxCZgeCwe
@sonarqubecloud

sonarqubecloud Bot commented Nov 4, 2026

Copy link
Copy Markdown

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.

MetadataFile.FindLocation(anchor, needle) points at the wrong entry when the anchor or needle is part of a longer name ("Meter" lands on "SquareMeter")

2 participants