Skip to content

Commit a515918

Browse files
committed
wip: check if ! is present in path
1 parent c65fb74 commit a515918

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

schemas/ajv.absolutePath.js

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
11
"use strict";
22

33
const getErrorFor = (shouldBeAbsolute, data, schema) => {
4-
const message = shouldBeAbsolute ?
5-
`The provided value ${JSON.stringify(data)} is not an absolute path!`
6-
: `A relative path is expected. However the provided value ${JSON.stringify(data)} is an absolute path!`;
4+
const message = shouldBeAbsolute
5+
? `The provided value ${JSON.stringify(data)} is not an absolute path!`
6+
: `A relative path is expected. However the provided value ${JSON.stringify(
7+
data
8+
)} is an absolute path!`;
79

810
return {
911
keyword: "absolutePath",
1012
params: { absolutePath: data },
1113
message: message,
12-
parentSchema: schema,
14+
parentSchema: schema
1315
};
1416
};
15-
module.exports = (ajv) => ajv.addKeyword("absolutePath", {
16-
errors: true,
17-
type: "string",
18-
compile(expected, schema) {
19-
function callback(data) {
20-
const passes = expected === /^(?:[A-Za-z]:\\|\/)/.test(data);
21-
if(!passes) {
22-
callback.errors = [getErrorFor(expected, data, schema)];
17+
18+
module.exports = ajv =>
19+
ajv.addKeyword("absolutePath", {
20+
errors: true,
21+
type: "string",
22+
compile(expected, schema) {
23+
function callback(data) {
24+
const passes = expected === /^(?!(?:[A-Za-z]:\\|\/).*!)/.test(data);
25+
if (!passes) {
26+
callback.errors.push(getErrorFor(expected, data, schema));
27+
}
28+
return passes;
2329
}
24-
return passes;
30+
callback.errors = [];
31+
return callback;
2532
}
26-
callback.errors = [];
27-
return callback;
28-
}
29-
});
33+
});

0 commit comments

Comments
 (0)