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

possibly Invalid pattern for Passphrase #480

Open
commonism opened this issue Jul 25, 2024 · 4 comments
Open

possibly Invalid pattern for Passphrase #480

commonism opened this issue Jul 25, 2024 · 4 comments

Comments

@commonism
Copy link

The regex

          pattern: (^[ !#-~]+$)|(^Passphrase:[ ^[ !#-~]+$)|(^Hex:[0-9A-Fa-f]{24})|(^\*+$)
          pattern: (^[ !#-~]+$)|(^Passphrase:[ ^[ !#-~]+$)|(^Hex:[0-9A-Fa-f]{24,96})|(^\*+$)
          pattern: (^[ !#-~]+$)|(^Passphrase:[ ^[ !#-~]+$)|(^Hex:[0-9A-Fa-f]{32})|(^\*+$)

are considered invalid by rust regex.

  SchemaError: regex parse error:
    (^[ !#-~]+$)|(^Passphrase:[ ^[ !#-~]+$)|(^Hex:[0-9A-Fa-f]{24,96})|(^\*+$)
                              ^
error: unclosed character class

It's accepted by python re.

Yet I think it lacks an escape for the [ in ^[

(^Passphrase:[ ^\[ !#-~]+$)
@mraineri
Copy link
Contributor

Thanks for catching these! I'll raise them to the rest of the group

@mraineri
Copy link
Contributor

At least other regex tools seem to allow for this... I'll need to see if I can get something up myself in Rust to check things out...

@mraineri
Copy link
Contributor

mraineri commented Jul 25, 2024

Looking into this a bit, and I suspect escaping the [ is not correct; I think the intended regex is:

(^Passphrase: [^ !#\-~]+$)

Update: Disregard; I'm working with someone on what the format really needs to be.

@commonism
Copy link
Author

commonism commented Jul 26, 2024

As #-~ is a range

''.join(chr(i) for i in range(ord("#"),ord("~")+1))
"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"

which already includes [ and ^ - …, we'll see where this ends up.

You can make use of rust regex via

from pydantic import BaseModel, Field

class B(BaseModel):
#    model_config = dict(regex_engine="python-re")
    v: str = Field(pattern=r"(^[ !#-~]+$)|(^Passphrase:[ ^[ !#-~]+$)|(^Hex:[0-9A-Fa-f]{24,96})|(^\*+$)")

It'll bail out.

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

No branches or pull requests

2 participants