Skip to content
This repository has been archived by the owner on Jan 2, 2023. It is now read-only.

Values stored in groups don't retain the original types #24

Open
aymanfarhat opened this issue Oct 9, 2020 · 0 comments
Open

Values stored in groups don't retain the original types #24

aymanfarhat opened this issue Oct 9, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@aymanfarhat
Copy link
Member

I was using the regex groups features and noticed that for fields with non-string type values e.g. numbers, boolean etc..., end up being cast into string when they are added into the groups object in the result. The matches object in the result seems to be normal.

Here is an example test to illustrate

  test('Maintain types in groups', () => {
    const payload = {
      response: {
        status: 200,
        _transferSize: 2863
      },
    }

    const result = match(payload, {
      response: {
        status: /^(?<respStatus>[0-9]{3})/,
        _transferSize: /(?<respSize>\d+)/,
      }
    })

    const expected = {
      match: true,
      total: 2,
      matches: {
        response: {
          status: 200,
          _transferSize: 2863
        }
      },
      groups: {
        respStatus: 200,
        respSize: 2863
      }
    }

    assert.isTrue(result.match)
    assert.deepEqual(result, expected)
  })

Test result

      AssertionError: expected { Object (match, total, ...) } to deeply equal { Object (match, total, ...) }
      + expected - actual

       {
         "groups": {
      -    "respSize": "2863"
      -    "respStatus": "200"
      +    "respSize": 2863
      +    "respStatus": 200
         }
         "match": true
         "matches": {
           "response": {

We might want to look into this issue, especially if the user is actually writing a regex group in the pattern to be matching by specific type.

@aymanfarhat aymanfarhat added the enhancement New feature or request label Oct 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant