Skip to content

Commit 6820a83

Browse files
committed
Merge branch 'CroniD-master'
2 parents 27f8c84 + aaa32d8 commit 6820a83

File tree

2 files changed

+144
-11
lines changed

2 files changed

+144
-11
lines changed

index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ runTest(4);
1515
runTest(6);
1616

1717
function runTest(draft) {
18-
var opts = {format: 'full'};
18+
var opts = {
19+
format: 'full',
20+
formats: {'json-pointer': /^(?:\/(?:[^~\/]|~0|~1)*)*$/}
21+
};
1922
if (draft == 4) opts.meta = false;
2023
var ajv = new Ajv(opts);
2124
ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json'));

tests/draft6/optional/format.json

Lines changed: 140 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@
220220
]
221221
},
222222
{
223-
"description": "validation of JSON-pointers",
223+
"description": "validation of JSON-pointers (JSON String Representation)",
224224
"schema": {"format": "json-pointer"},
225225
"tests": [
226226
{
@@ -229,29 +229,159 @@
229229
"valid": true
230230
},
231231
{
232-
"description": "empty string is valid",
232+
"description": "not a valid JSON-pointer (~ not escaped)",
233+
"data": "/foo/bar~",
234+
"valid": false
235+
},
236+
{
237+
"description": "valid JSON-pointer with empty segment",
238+
"data": "/foo//bar",
239+
"valid": true
240+
},
241+
{
242+
"description": "valid JSON-pointer with the last empty segment",
243+
"data": "/foo/bar/",
244+
"valid": true
245+
},
246+
{
247+
"description": "valid JSON-pointer as stated in RFC 6901 #1",
233248
"data": "",
234249
"valid": true
235250
},
236251
{
237-
"description": "/ is valid",
252+
"description": "valid JSON-pointer as stated in RFC 6901 #2",
253+
"data": "/foo",
254+
"valid": true
255+
},
256+
{
257+
"description": "valid JSON-pointer as stated in RFC 6901 #3",
258+
"data": "/foo/0",
259+
"valid": true
260+
},
261+
{
262+
"description": "valid JSON-pointer as stated in RFC 6901 #4",
238263
"data": "/",
239264
"valid": true
240265
},
241266
{
242-
"description": "not a valid JSON-pointer (~ not escaped)",
243-
"data": "/foo/bar~",
244-
"valid": false
267+
"description": "valid JSON-pointer as stated in RFC 6901 #5",
268+
"data": "/a~1b",
269+
"valid": true
245270
},
246271
{
247-
"description": "valid JSON-pointer with empty segment",
248-
"data": "/foo//bar",
272+
"description": "valid JSON-pointer as stated in RFC 6901 #6",
273+
"data": "/c%d",
249274
"valid": true
250275
},
251276
{
252-
"description": "valid JSON-pointer with the last empty segment",
253-
"data": "/foo/bar/",
277+
"description": "valid JSON-pointer as stated in RFC 6901 #7",
278+
"data": "/e^f",
279+
"valid": true
280+
},
281+
{
282+
"description": "valid JSON-pointer as stated in RFC 6901 #8",
283+
"data": "/g|h",
284+
"valid": true
285+
},
286+
{
287+
"description": "valid JSON-pointer as stated in RFC 6901 #9",
288+
"data": "/i\\j",
289+
"valid": true
290+
},
291+
{
292+
"description": "valid JSON-pointer as stated in RFC 6901 #10",
293+
"data": "/k\"l",
294+
"valid": true
295+
},
296+
{
297+
"description": "valid JSON-pointer as stated in RFC 6901 #11",
298+
"data": "/ ",
299+
"valid": true
300+
},
301+
{
302+
"description": "valid JSON-pointer as stated in RFC 6901 #12",
303+
"data": "/m~0n",
304+
"valid": true
305+
},
306+
{
307+
"description": "valid JSON-pointer used to add something to the last position of an array",
308+
"data": "/foo/-",
309+
"valid": true
310+
},
311+
{
312+
"description": "valid JSON-pointer (- used as object member name)",
313+
"data": "/foo/-/bar",
314+
"valid": true
315+
},
316+
{
317+
"description": "valid JSON-pointer (multiple escaped characters)",
318+
"data": "/~1~0~0~1~1",
319+
"valid": true
320+
},
321+
{
322+
"description": "valid JSON-pointer (escaped characters with fraction part) #1",
323+
"data": "/~1.1",
254324
"valid": true
325+
},
326+
{
327+
"description": "valid JSON-pointer (escaped characters with fraction part) #2",
328+
"data": "/~0.1",
329+
"valid": true
330+
},
331+
{
332+
"description": "not a valid JSON-pointer (URI Fragment Identifier Representation) #1",
333+
"data": "#",
334+
"valid": false
335+
},
336+
{
337+
"description": "not a valid JSON-pointer (URI Fragment Identifier Representation) #2",
338+
"data": "#/",
339+
"valid": false
340+
},
341+
{
342+
"description": "not a valid JSON-pointer (URI Fragment Identifier)",
343+
"data": "#a",
344+
"valid": false
345+
},
346+
{
347+
"description": "not a valid JSON-pointer (some escaped, but not all) #1",
348+
"data": "/~0~",
349+
"valid": false
350+
},
351+
{
352+
"description": "not a valid JSON-pointer (some escaped, but not all) #2",
353+
"data": "/~0/~",
354+
"valid": false
355+
},
356+
{
357+
"description": "not a valid JSON-pointer (wrong escape character) #1",
358+
"data": "/~2",
359+
"valid": false
360+
},
361+
{
362+
"description": "not a valid JSON-pointer (wrong escape character) #2",
363+
"data": "/~-1",
364+
"valid": false
365+
},
366+
{
367+
"description": "not a valid JSON-pointer (multiple characters not escaped)",
368+
"data": "/~~",
369+
"valid": false
370+
},
371+
{
372+
"description": "not a valid JSON-pointer (isn't empty nor starts with /) #1",
373+
"data": "a",
374+
"valid": false
375+
},
376+
{
377+
"description": "not a valid JSON-pointer (isn't empty nor starts with /) #2",
378+
"data": "0",
379+
"valid": false
380+
},
381+
{
382+
"description": "not a valid JSON-pointer (isn't empty nor starts with /) #2",
383+
"data": "a/a",
384+
"valid": false
255385
}
256386
]
257387
}

0 commit comments

Comments
 (0)