False positive error for a valid regex pattern
altego371 opened this issue · 1 comments
altego371 commented
The package returns a false positive error for a valid regex pattern in a schema.
Pattern .{1,1024}$
is valid, but CompileString
method returns an error.
Empirically established that an error is returned for any value greater than 1000. For a value less than or equal to 1000, the error does not occur.
The package version is 5.2.0
The code below shows the bug
package bug
import (
"github.com/santhosh-tekuri/jsonschema/v5"
"github.com/stretchr/testify/assert"
"strings"
"testing"
)
func TestBugInJsonschemaPackage(t *testing.T) {
validSchema := `
{
"type": "object",
"properties": {
"description": {"type": "string", "pattern": ".{1,1024}$"}
}
}
`
_, falsePositiveError := jsonschema.CompileString("", validSchema)
assert.ErrorContains(t, falsePositiveError, `'.{1,1024}$' is not valid 'regex'`)
updatedSchema := strings.Replace(validSchema, `".{1,1024}$"`, `".{1,1000}$"`, 1)
_, err := jsonschema.CompileString("", updatedSchema)
assert.NoError(t, err)
}
santhosh-tekuri commented
WONT_FIX
this package uses golang regexp package which has this limitation.
https://github.com/google/re2/wiki/Syntax clearly says:
Implementation restriction: The counting forms x{n,m}, x{n,}, and x{n} reject forms
that create a minimum or maximum repetition count above 1000.
Unlimited repetitions are not subject to this restriction.