fix(utils): harden parseAttributes against non-JSON attribute values#92
Open
Sentinel-Bluebuilder wants to merge 1 commit into
Conversation
`JSON.parse(x.value)` throws on raw-string attribute values, breaking the entire event parse for that tx. Cosmos SDK >=0.50 emits attribute values as plain strings (no JSON quoting), so any chain past 0.47 hits this immediately on real events. Wrap the parse in try/catch and fall back to the raw string. Already-JSON values still parse identically; only behavior change is that raw strings round-trip as raw strings instead of throwing.
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.
Summary
JSON.parse(x.value)in `parseAttributes` throws on raw-string attribute values. Cosmos SDK >=0.50 emits event attribute values as plain strings (no JSON quoting), so on any chain past 0.47, calling `parseAttributes` on a real event with one non-JSON attribute crashes the entire parse for that tx.Sentinel chain hasn't bitten this yet because of where it sits on the SDK fork tree, but every consumer using this helper against another Cosmos chain hits it on day 1, and it will bite once Sentinel rebases.
Diff
```diff
export function parseAttributes(attributes: readonly Attribute[] | Attribute[]): any {
}
```
Why this is safe
Already-JSON values still parse identically. The only behavior change is raw strings round-trip as raw strings instead of throwing. No reasonable consumer was relying on the throw — a thrown `parseAttributes` is always a bug at the call site.
Test plan