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

Configure regex validation to be case insensitive #173

Closed
luizpericolo opened this Issue Nov 23, 2015 · 5 comments

Comments

Projects
None yet
3 participants
@luizpericolo
Copy link

luizpericolo commented Nov 23, 2015

I know it is not possible to express case insensitivity flag in the actual regex string in python, so I guess that cerberus could use another attribute to manage this, for instance: regex_case.

@funkyfuture

This comment has been minimized.

Copy link
Member

funkyfuture commented Nov 24, 2015

you could fiddle around with the anyof-rule (or similar) and lower/upper-methods of strings. could you?

@luizpericolo

This comment has been minimized.

Copy link

luizpericolo commented Nov 24, 2015

This does not sound optimal since I'd have to have two versions of my regex, the lower and the upper case version, if I were to use anyof as you suggested. This is bad because If anything on the regex changes I have to change it on the other version aswell.

@luizpericolo

This comment has been minimized.

Copy link

luizpericolo commented Nov 24, 2015

I'm debugging the regex validation process and I realize that my suggestion might not be feasible.
Maybe you could add a regex_case attribute to the Validator constructor, but I don't know if that does really make sense, specially if you would like some regex to be case sensitive and others not.

I'd be willing to contribute to this, but I just can't think of a good solution for this problem.

@luizpericolo

This comment has been minimized.

Copy link

luizpericolo commented Nov 24, 2015

Maybe change the regex key mapping from str to dict would be a good solution.
Something along the lines of:

data_format = {
    'name': {
        'type': 'string',
        'regex': {
            'pattern': r'^[a-z0-9]$', 
            'case': 'insensitive'
        }
    }
}

The problem then would be how to maintain backwards compatibility to the current syntax of regex validation.

@funkyfuture

This comment has been minimized.

Copy link
Member

funkyfuture commented Nov 25, 2015

maintaining backward compatibility wouldn't be a problem. (duck-typing per instance-tests, you'll find a lot of these in the code.)
however, i suggest to name the second parameter flags and let that be an integer like the parameter with the same name for re.compile.

funkyfuture added a commit to funkyfuture/cerberus that referenced this issue Oct 26, 2016

funkyfuture added a commit to funkyfuture/cerberus that referenced this issue Oct 26, 2016

funkyfuture added a commit to funkyfuture/cerberus that referenced this issue Oct 26, 2016

@nicolaiarocci nicolaiarocci added this to the Unreleased milestone Oct 27, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment