-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to access object property with a space in its key via expression templates #2974
Comments
My usual debugging strategy works yet again:
For anyone who runs into this problem, the correct syntax is |
Never mind... I'm now getting the same error when the value isn't an object like in the 3rd example above... value: 'actual value I need to access' Trying to find a workaround for this now. |
I got this PR up on the formula repo that solves the issue in the above comment: hapijs/formula#14 As I mentioned in the PR, I'm not sure if there's a deeper issue that needs to be resolved here, but this fixes my issue and it seems like a sensible change to me. |
Hi, and sorry for the delay. Could you maybe submit a failing unit test? Because I'm having troubles reproducing the issue on my side. From what I'm seeing, it could be a misunderstanding of the template syntax, which is not exactly javascript. I think your formula should be written like this: I'm still interested in understanding the reasons for this stacktrace though, so I'll hold your PR until I can see how to debug it myself. |
Yeah, that's the formula that I'm using now (is the syntax I was referring to in the first reply I made here). Here's a PR with unit tests showing the cases where the bug is occurring: #2985 (probably could've used a simpler schema without the As you can see, that syntax is throwing the error anytime I didn't include examples to show this part: this bug seems to only be happening when the formula includes the object property with spaces (ie, |
Thanks a lot for your patience and for your efforts in trying to fix this. After digging, I decided to change joi's resolve function instead of changing formula's. Hopefully I'm not breaking anyone's code while still fixing the issue. I'm pretty sure it will fix your use case, but do let know if not. |
sounds good, thanks! is this already in a release or expected for an upcoming one? |
It's already released in 17.10.2 |
confirmed that it's working now, thanks!! |
Hi, I'm attempting to access a property on an object that contains a space in the property's key.
I've got a value that could be structured as any of the following:
value: 'actual value I need to access'
And I'm trying to use this syntax to capture all possible structures (my actual error case is
array.unique
, but that's beside the point so I reduced this to a single value rather thanvalue
+dupeValue
):Invalid frequency ratio: "{#value.ratio || #value["frequency ratio"] || #value}"
The dot notation accessor works fine, but the bracket notation accessor results in this error:
TypeError: Cannot read properties of undefined (reading 'Symbol(formula)')
Here's the relevant stack trace:
I see that brackets are parsed out in the formula library due to being treated as literals, so I've tried various other things to get past this, but nothing that I've tried is working. Is this just a current limitation, or is there a workaround that I'm not finding?
Thanks!
The text was updated successfully, but these errors were encountered: