ajv-validator / ajv-validator/ajv

Firefox: Select with over 250 options - InternalError: function nested too deeply

Đang mở
#2,530 5 bình luận 1 reaction 0 người được giao Xem trên GitHub
bug report
Ngôn ngữ chính
TypeScript
Star
14.8k
Fork
1k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

**What version of Ajv are you using? Does the issue happen if you use the latest version?**
I use Ajv Version 8.17.1 and the issue still happens

**Ajv options object**

```javascript
const ajv = new Ajv({ strict: false });
```

**JSON Schema**

```json
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"select_string_type": {
"type": "string",
"oneOf": [
{
"const": "test_1",
"title": "test_1"
},
{
"const": "test_2",
"title": "test_2"
},{
"const": "test_3",
"title": "test_3"
},{
"const": "test_4",
"title": "test_4"
},{
"const": "test_5",
"title": "test_5"
},
...
{
"const": "test_294",
"title": "test_294"
},{
"const": "test_295",
"title": "test_295"
},{
"const": "test_296",
"title": "test_296"
},{
"const": "test_297",
"title": "test_297"
},{
"const": "test_298",
"title": "test_298"
},{
"const": "test_299",
"title": "test_299"
},{
"const": "test_300",
"title": "test_300"
}
],
"title": "__(SELECT_STRING)",
"x-jsf-presentation": {
"inputType": "select"
}
},
"select_number_type": {
"type": "number",
"oneOf": [
{
"const": 0,
"title": "one"
},
{
"const": 1,
"title": "two"
}
],
"title": "__(SELECT_NUMBER)",
"x-jsf-presentation": {
"inputType": "select"
}
},
"string_type": {
"type": "string",
"title": "__(STRING)",
"maxLength": 64,
"x-jsf-presentation": {
"inputType": "text"
}
}
},
"allOf": [
{
"if": {
"properties": {
"select_number_type": {
"const": 0
}
}
},
"then": {
"properties": {
"string_type": {
"minLength": 1,
"maxLength": 64
}
},
"required": [
"string_type"
]
},
"else": {
"properties": {
"string_type": {
"x-jsf-presentation": {
"inputType": "hidden"
}
}
}
}
}
],
"required": [
"select_string_type",
"select_number_type"
]
}
```

**Sample data**

```json
{
"select_string_type": "test_1",
"select_number_type": 0,
"string_type": "string example"
}

```

**Your code**

```javascript

import { ref } from "vue";
import Ajv from "ajv";
import schema from "./../assets/schema/schema.json?raw";

const elements_select_string = ref([
"test_1",
"test_2",
"test_3",
"test_4",
...
"test_297",
"test_298",
"test_299",
"test_300",
]);

const selectStringElement = ref("");
const selectNumberElement = ref(0);
const stringElement = ref("string example");

async function createJSON() {
let config = {
jsonFile: {
version: "0.1.0",
form: {
select_string_type: selectStringElement.value,
select_number_type: selectNumberElement.value,
string_type: stringElement.value,
},
},
};

await validateJSON(config);
}

async function validateJSON(config) {
const ajv = new Ajv({ strict: false });

try {
const validate = ajv.compile(JSON.parse(schema));
const valid = validate(config.jsonFile.form);

if (valid) {
console.log("JSON valid");
} else {
console.log("JSON invalid", validate.errors);
}
} catch (error) {
console.error("Error:", error);
}
}


Example



Choose Select String Type:


{{ select }}



Choose Select Number Type:

one
two


String Type:




```

**Validation result, data AFTER validation, error messages**

```
Error: InternalError: function nested too deeply
validateJSON HelloWorld.vue:333
createJSON HelloWorld.vue:325
callWithErrorHandling runtime-core.esm-bundler.js:199
callWithAsyncErrorHandling runtime-core.esm-bundler.js:206
invoker runtime-dom.esm-bundler.js:729
addEventListener runtime-dom.esm-bundler.js:680
patchEvent runtime-dom.esm-bundler.js:698
patchProp runtime-dom.esm-bundler.js:775
mountElement runtime-core.esm-bundler.js:4873
processElement runtime-core.esm-bundler.js:4820
patch runtime-core.esm-bundler.js:4688
mountChildren runtime-core.esm-bundler.js:4932
mountElement runtime-core.esm-bundler.js:4855
processElement runtime-core.esm-bundler.js:4820
patch runtime-core.esm-bundler.js:4688
mountChildren runtime-core.esm-bundler.js:4932
mountElement runtime-core.esm-bundler.js:4855
processElement runtime-core.esm-bundler.js:4820
patch runtime-core.esm-bundler.js:4688
componentUpdateFn runtime-core.esm-bundler.js:5326
run reactivity.esm-bundler.js:225
setupRenderEffect runtime-core.esm-bundler.js:5454
mountComponent runtime-core.esm-bundler.js:5229
processComponent runtime-core.esm-bundler.js:5182
patch runtime-core.esm-bundler.js:4700
componentUpdateFn runtime-core.esm-bundler.js:5326
run reactivity.esm-bundler.js:225
setupRenderEffect runtime-core.esm-bundler.js:5454
mountComponent runtime-core.esm-bundler.js:5229
processComponent runtime-core.esm-bundler.js:5182
patch runtime-core.esm-bundler.js:4700
render2 runtime-core.esm-bundler.js:5979
mount runtime-core.esm-bundler.js:3941
mount runtime-dom.esm-bundler.js:1767
main.js:11
HelloWorld.vue:341:12

```

**What results did you expect?**
When using Chrome, the validation works without any problems. When using Firefox, this issue occurs without any changes made. I tried different approaches with the parameters, but nothing seems to work. As soon as there are more than 250 options, this error occurs.

This issue is happening when using AJV in a Vue.js project with Composition API.

I've added the Vue project below. You can unpack it and run ```npm run dev``` in the folder where the entire project is located.

[ajv_error.zip](https://github.com/user-attachments/files/18573986/ajv_error.zip)

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.