Closed hobgoblina closed 1 year ago
My usual debugging strategy works yet again:
For anyone who runs into this problem, the correct syntax is #value.[property key with spaces]
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: https://github.com/hapijs/formula/pull/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: "{#value.ratio || #value.[frequency ratio] || #value}"
. As mentioned in the docs, square brackets are there to disambiguate references, it's not an accessor.
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: https://github.com/hapijs/joi/pull/2985 (probably could've used a simpler schema without the unique
, but I just modified the schema I'm using since it's what's failing for me)
As you can see, that syntax is throwing the error anytime #value
isn't an object.
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, #value.[frequency ratio]
... or #value.[var with spaces]
in the unit tests). If I make the formula "{#value.ratio || #value}"
then I don't have any issues (aside from it not covering all possible cases 😛).
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:
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!