usebruno / bruno

Opensource IDE For Exploring and Testing Api's (lightweight alternative to postman/insomnia)
https://www.usebruno.com/
MIT License
21.54k stars 1.01k forks source link

Assertion Fails on JSON field with invalid character (hyphen) #2474

Open fgrande opened 1 week ago

fgrande commented 1 week ago

I have checked the following:

Describe the bug

Asserting a field that contains an hyphen in its name result in an error. For instance, in the associated bru file, the assert

res.body.life-span.begin: eq "1989"

result in a problem, since "life-span" is not a valid js fieldname

Trying to attach a PR that would solve the issue

.bru file to reproduce the bug

MusicBrainz JSON.bru.zip

Screenshots/Live demo link

image
fgrande commented 1 week ago

PR #2475

lohxt1 commented 1 week ago

writing the expression like below should work

res.body?.['life-span']?.begin

fgrande commented 1 week ago

@lohxt1 I confirm it works, thanks a lot for the hint. Actually it works also as "res.body['life-span'].begin" Anyway, wouldn't it be nice to write it in a simpler way ?