WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Subexpressions containing subexpressions not handled #5

@NigelThorne

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
        }
      ]
    }
  ]
}

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