Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regex generator panic #311

Closed
tienvx opened this issue Aug 10, 2023 · 3 comments
Closed

Regex generator panic #311

tienvx opened this issue Aug 10, 2023 · 3 comments

Comments

@tienvx
Copy link
Contributor

tienvx commented Aug 10, 2023

Matchers (pact-js):

'hydra:member': eachLike({
    'family': {
        'pact:matcher:type': 'regex',
        'pact:generator:type': 'Regex',
        regex: '^\/api\/families\/[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$',
    },
    'gender': {
        'pact:matcher:type': 'regex',
        'pact:generator:type': 'Regex',
        regex: '(male|female|other)',
    }
})

While the generator for the field gender worked, the generator for the field family panic then stop the mock server.

Log:

2023-08-10T05:09:46.588700Z DEBUG tokio-runtime-worker pact_models::generators: Applying generator Regex("(male|female|other)") to key $['hydra:member'][*].gender
2023-08-10T05:09:46.588718Z DEBUG tokio-runtime-worker pact_models::generators: Generating value from Regex("(male|female|other)") context={"mockServer": Object {"port": Number(36037), "url": String("http://127.0.0.1:36037")}}
2023-08-10T05:09:46.588748Z DEBUG tokio-runtime-worker pact_models::generators: Generated value = Ok(String("other"))
2023-08-10T05:09:46.588751Z DEBUG tokio-runtime-worker pact_models::generators: Applying generator Regex("^/api/families/[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$") to key $['hydra:member'][*].family
2023-08-10T05:09:46.588761Z DEBUG tokio-runtime-worker pact_models::generators: Generating value from Regex("^/api/families/[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$") context={"mockServer": Object {"port": Number(36037), "url": String("http://127.0.0.1:36037")}}
thread 'tokio-runtime-worker' panicked at 'called `Result::unwrap()` on an `Err` value: Anchor', /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/pact_models-1.1.9/src/generators/mod.rs:1041:60

Info:

  • Specification: v4
  • Pact JS: 12.1.0
  • Pact Rust:
    • FFI: 0.4.7
    • Models: 1.1.9
@rholshausen
Copy link
Contributor

Looks like rand_regex crate does not support anchors in the regex

Returns an error if the Hir object contains anchors (^, $, \A, \z) or word boundary assertions (\b, \B).

@tienvx
Copy link
Contributor Author

tienvx commented Aug 10, 2023

I tried remove anchors ^ and $ and it work fine. Should I keep this issue or close it as won't fix?

@rholshausen
Copy link
Contributor

It needs to be fixed, it shouldn't ever just panic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Closed
Development

No branches or pull requests

2 participants