pact-foundation / pact-reference

Reference implementations for the pact specifications
https://pact.io
MIT License
91 stars 46 forks source link

Regex generator panic #311

Closed tienvx closed 4 months ago

tienvx commented 11 months ago

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:

rholshausen commented 11 months ago

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 commented 11 months ago

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

rholshausen commented 11 months ago

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