Skip to content

Commit 6651088

Browse files
committed
feat: allow file:// protocol prefix in absolute paths
1 parent 3b103ae commit 6651088

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

‎src/keywords/absolutePath.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,12 @@ function addAbsolutePathKeyword(ajv) {
7070
passes = false;
7171
}
7272

73+
// (?:file:\/\/)? - optional file:// protocol prefix
7374
// ?:[A-Za-z]:\\ - Windows absolute path
7475
// \\\\ - Windows network absolute path
7576
// \/ - Unix-like OS absolute path
7677
const isCorrectAbsolutePath =
77-
schema === /^(?:[A-Za-z]:(\\|\/)|\\\\|\/)/.test(data);
78+
schema === /^(?:file:\/\/)?(?:[A-Za-z]:(\\|\/)|\\\\|\/)/.test(data);
7879

7980
if (!isCorrectAbsolutePath) {
8081
callback.errors = [getErrorFor(schema, parentSchema, data)];

‎test/index.test.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,14 @@ describe("validation", () => {
325325
testAbsolutePath: "//server/directory/deep/tree",
326326
});
327327

328+
createSuccessTestCase("absolutePath #6", {
329+
testAbsolutePath: "file:///Users/username/directory/deep/tree",
330+
});
331+
332+
createSuccessTestCase("absolutePath #7", {
333+
testAbsolutePath: "file:///C:/directory/deep/tree",
334+
});
335+
328336
createSuccessTestCase("$data", {
329337
dollarData: {
330338
smaller: 5,

0 commit comments

Comments
 (0)