Skip to content

Pattern implementation doesn't support ECMA 262 #985

Closed
@Emptyless

Description

@Emptyless

The OpenAPI documentation for pattern specifies that it implements the ECMA 262 specification. ECMA 262 :: 15.10.2.8 - Atom specifies support for positive lookahead:

NOTE 2

The form (?= Disjunction ) specifies a zero-width positive lookahead. In order for it to succeed, the pattern inside Disjunction must match at the current position, but the current position is not advanced before matching the sequel. If Disjunction can match at the current position in several ways, only the first one is tried. Unlike other regular expression operators, there is no backtracking into a (?= form (this unusual behaviour is inherited from Perl). This only matters when the Disjunction contains capturing parentheses and the sequel of the pattern contains backreferences to those captures.

The current implementation parses the schema's using the Go standard library. The regexp package however does not support the positive lookahead (see e.g. golang/go#18868).

Why would this be relevant? Because in OpenAPI this can be used for concatenating pattern checks, see e.g. Combine Regexp. A simple example:

type: string
pattern: '^(?=^(?:(?![A-Z]).)*$)(?=[\x00-\x7F]*).*$'

which checks that the input is lowercased and only contains ascii characters.

The following would then depend on a library implementing ECMA262, e.g. dlclark/regexp2:

if cp, err = regexp.Compile(intoGoRegexp(pattern)); err != nil {

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions