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

validators: add option for non-ECMA regex validation #103

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

omriarad
Copy link

@omriarad omriarad commented Jan 8, 2018

this allows more flexibility with exporting the generated schema with other implementations.
according to the JSON schema the pattern SHOULD be ECMA but not necessarily.

Implements #102

this allows more flexibility with exporting the generated schema with other implementations.
according to the JSON schema the pattern SHOULD be ECMA but not necessarily.

Signed-off-by: Omri Arad <[email protected]>
flags.update(
{key: self.ECMA_FLAGS[key] in result.flags})

self.flags = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks compatibility with current code, and contradicts the comment at the head of the function:

Note, that if given pattern is ECMA regex, given flags will be
completely ignored and taken from given regex.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it appears that actually the code comment is incorrect :(

Ignore my comment.

@@ -221,6 +221,22 @@ class Person(models.Base):
person.name = 'Jimmy'


def test_regex_modify_schema():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some missing test cases:

  1. Invalid flags
  2. Flags provided directly in an ECMA262 pattern
  3. Flags passed with **flags

@beregond
Copy link
Collaborator

Nice, but actually since this is going to be some 'generic' validator - why not create other class for it? I mean ecma=True is just a switch that changes most of bahaviour - it should be distinct validators.GenericRegex - you could simply copy actual Regex and remove flags, translation etc*.

(*Actually since this is generic regex you could/should remove actual validation too - if you don't know what language it is in - you cannot validate it. And if you know (that this is ie PCRE or python expression then such class wouldn't be generic either.)

@avrahamshukron
Copy link
Contributor

In that case maybe validators.PythonRegex class might make sense since we do want to actually validate the value.

@beregond
Copy link
Collaborator

beregond commented Feb 3, 2018

Yeah, this would make sense actually, but alongside ECMARegex would be required too. And we cannot remove Regex class anyway for backward compatibility.

@avrahamshukron
Copy link
Contributor

Will work on that soon.

In any case the lack of this validator is not a big deal since the library enables anyone to write such validator themselves

@avrahamshukron
Copy link
Contributor

I think this PR should be closed since it is followed by #108 which fixes the issues with this PR.

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

Successfully merging this pull request may close these issues.

3 participants