Skip to content

bug: ogenregex can't handle \p used ECMA-262 regexp pattern #1466

@repeatedly

Description

@repeatedly

Thanks for great project. ogen helps our company products :)

What version of ogen are you using?

$ go list -m github.com/ogen-go/ogen
github.com/ogen-go/ogen v1.13.1-0.20250526152536-f794c2de6f94

Can this issue be reproduced with the latest version?

Yes

What did you do?

I have OpenAPI schema which uses following regex pattern:

      "Name": {
        "type": "string",
        "description": "Allow Unicode char, Number, -, _ and .",
        "minLength": 1,
        "maxLength": 255,
        "example": "name",
        "pattern": "^[\\p{L}\\p{N}._\\-]+$"
      },

I created client library with ogen and I got validation error like below:

validate: invalid: name (string: no regex match: ^[\p{L}\p{N}._\-]+$)

Here is the test code based on ogenregex.

	converted, ok := ogenregex.Convert("^[\\p{L}\\p{N}._\\-]+$")
	if !ok {
		fmt.Println("Can't converting pattern")
		return
	}
	fmt.Printf("Converted regex: %v\n", converted)  // I think converted pattern is wrong

	re := ogenregex.MustCompile("^[\\p{L}\\p{N}._\\-]+$")
	fmt.Printf("Regex type: %v\n", reflect.TypeOf(re))

	val, _ := re.MatchString("test-service")
	fmt.Printf("Regex match: %v\n", val)

	re2, _ := regexp2.Compile("^[\\p{L}\\p{N}._\\-]+$", regexp2.ECMAScript|regexp2.Unicode)
	val2, _ := re2.MatchString("test-service")
	fmt.Printf("Regex2 match: %v\n", val2)  // regexp2 works well

Test result:

Converted regex: ^[p{L}p{N}._\-]+$
Regex type: ogenregex.goRegexp
Regex match: false
Regex2 match: true

What did you expect to see?

ogenregex.MustCompile handles \p \ \P, Unicode character class escape, used ECMA-262 regexp pattern properly.
Use regexp2 for this case or ogenregex.Convert supports Unicode character class escape

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions