ajv-validator / ajv-validator/ajv

JTD parser fails on empty array that has whitespace between brackets

Offen
#2,595 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
bug report
Vorherrschende Sprache
TypeScript
Sterne
14.8k
Forks
1k
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

**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`.

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.