DMTF / Redfish-Tools

DMTF-produced tools to support the Redfish Specification
Other
81 stars 35 forks source link

possibly Invalid pattern for Passphrase #480

Open commonism opened 1 month ago

commonism commented 1 month ago

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 commented 1 month ago

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

mraineri commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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.