Skip to content

Subexpressions containing subexpressions not handled #5

Description

@NigelThorne

Expression like the following: $.Manufacturers..[?(@Products[?(@Name=='Elbow Grease')])] are not parsed correctly.

In Normalize the following code exists

RegExp.Replace(expr, @"[\['](\??\(.*?\))[\]']", m =>

This regex is not greedy, so the .* will match the minimum it can, so ?(@Products[?(@Name=='Elbow Grease') is matched, not ?(@Products[?(@Name=='Elbow Grease')])

Making it greedy doesn't solve all the problems either.

We could make it match the simple case (no internal sub expressions) and once matched, and replaced with a [#1] subsequently repeat the process until the string no longer changes.

Even once we get that working... we need to handle escaping of strings... What if Elbow Grease was a barcode that included a ')'.

My test data was as follows...

{
  'Stores': [
    'Lambton Quay',
    'Willis Street'
  ],
  'Manufacturers': [
    {
      'Name': 'Acme Co',
      'Products': [
        {
          'Name': 'Anvil',
          'Price': 50
        }
      ]
    },
    {
      'Name': 'Contoso',
      'Products': [
        {
          'Name': 'Elbow Grease',
          'Price': 99.95
        },
        {
          'Name': 'Headlight Fluid',
          'Price': 4
        }
      ]
    }
  ]
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions