Skip to content

Slash is not ignored in regexify() in some cases #382

@SCIF

Description

@SCIF

Summary

In some cases, like [a-z\-]{4} the slash in regex should be ignored. At least if we want to simulate php behavior. Currently, slash considered a valid character and «presents» in generated strings.

Versions

Version
PHP 8.0.8
fakerphp/faker 1.1.16

Self-enclosed code snippet for reproduction

for ($i = 0; $i<100; $i++) { 
    $v = \Faker\Factory::create()->regexify('[a-z\-]{4}'); 
    if (strlen($v) < 4) { 
        var_dump($v); 
    }
}

Expected output

Actual output

It fails in 7-10% of iteration in my setup. Producing output like

...
string(3) "srb"
string(3) "ncs"
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions