ajv-validator / ajv-validator/ajv
JTD parser fails on empty array that has whitespace between brackets
- Lingua principale
- TypeScript
- Stelle
- 14.8k
- Fork
- 1k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
**What version of Ajv are you using? Does the issue happen if you use the latest version?**
8.18.0 (latest at time of submission)
**Ajv options object**
```javascript
import Ajv, { JTDDataType } from "ajv/dist/jtd";
const ajv = new Ajv();
```
**JSON Type Definition**
```json
{"properties": { "data": { "elements": { "type": "string"} } }
```
**Sample data**
```json
{"data": [ ]}
```
**Your code**
```javascript
import Ajv, { JTDDataType } from "ajv/dist/jtd";
import schema from './schema.json'; // Contains JTD above
const ajv = new Ajv();
export type SchemaType = JTDDataType;
export const dataParser = ajv.compileParser(schema);
const text = `{"data": [ ]}`;
const parsedData = dataParser(text);
console.log(parsedData);
console.log(dataParser.message);
console.log(dataParser.position);
```
**Validation result, data AFTER validation, error messages**
```
undefined
unexpected token ]
10
```
**What results did you expect?**
Parser should not fail on an empty array that contains white spaces.
**Are you going to resolve the issue?**
I will open a PR. It is a one line fix - we just need to add `skipWhitespace(cxt)` to `lib/compile/jtd/parse.ts` in `parseElements` method before calling `parseItems`.
Guida per i contributori
Apri la guida per i contributori
Valutazione
Questa issue non è ancora stata valutata.