Skip to content

Fix interpretation of integer segment on objects - #519

Open
satabin wants to merge 1 commit into
mainfrom
pointer/int-field
Open

Fix interpretation of integer segment on objects#519
satabin wants to merge 1 commit into
mainfrom
pointer/int-field

Conversation

@satabin

@satabin satabin commented Sep 3, 2026

Copy link
Copy Markdown
Member

When the pointer segment is an integer and it is evaluated on an object, look for the field name being that integer instead of failing.

Fixes #517

Note: in this PR I also fixed some warnings. The diffson codebase shows its age sometimes and I never took the time to properly fix the imports and new conventions globally, at least I started doing it for this part of the code.

@satabin satabin added the bug label Sep 3, 2026
When the pointer segment is an integer and it is evaluated on an object,
look for the field name being that integer instead of failing.

Fixes #517
case (JsObject(obj), Inner(Left(elem), tl), parent) =>
F.pure(Left((obj.getOrElse(elem, Json.Null), tl, parent / elem)))
case (JsObject(obj), Inner(elem, tl), parent) =>
val fieldName = elem.fold(identity, _.toString())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggestion (optional): Use Integer.toString to make it more clear what we're converting, took me a moment (without IDE admittedly) to figure out we're not calling toString() on some arbitrary types here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Misinterpretation of numeric JSON Pointers as array indexes?

2 participants