Skip to content

Unable to access object property with a space in its key via expression templates #2974

@hobgoblina

Description

@hobgoblina

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: {
  ratio: 'actual value I need to access'
  // other properties
}
value: {
  'frequency ratio': 'actual value I need to access'
  // other properties
}
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 than value + 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:

      at Object.<anonymous>.internals.evaluate (node_modules/@sideway/formula/lib/index.js:385:13)
      at node_modules/@sideway/formula/lib/index.js:347:44
          at Array.forEach (<anonymous>)
      at Object.<anonymous>.exports.Parser.evaluate (node_modules/@sideway/formula/lib/index.js:342:34)
      at Object.<anonymous>.module.exports.internals.Template._part (node_modules/joi/lib/template.js:178:29)
      at Object.<anonymous>.module.exports.internals.Template.render (node_modules/joi/lib/template.js:193:39)

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!

Metadata

Metadata

Assignees

Labels

bugBug or defectsupportQuestions, discussions, and general support

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions