Skip to content

[Bug] Trailing newline in value to validate ignored when using regex #307

Description

@callumgare

The string a\n should fail validation with the schema Regex("^a$") but that does not happen. You can see this by running:

python3 -c 'from schema import Regex; Regex("^a$").validate("a\\n")'

This appears to only be true for a single trailing newline. Multiple trailing newlines or a leading newline both fail as expected:

python3 -c 'from schema import Regex; Regex("^a$").validate("a\\n\\n")' # this fails
python3 -c 'from schema import Regex; Regex("^a$").validate("\\na")' # as does this

I had a look though the existing issues but can't see this reported anywhere. I'm using the latest version (0.7.5) with Python 3.11.6 on macOS.

Thanks!

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