Skip to content

Commit

Permalink
fix: better handle absolute paths
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffin143 committed Jan 15, 2020
1 parent 45ecebc commit d8c74b6
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions schemas/ajv.absolutePath.js
Expand Up @@ -25,8 +25,6 @@ module.exports = ajv =>
function callback(data) {
let passes = true;
const isExclamationMarkPresent = data.includes("!");
const isCorrectAbsoluteOrRelativePath =
expected === /^(?:[A-Za-z]:\\|\/)/.test(data);

if (isExclamationMarkPresent) {
callback.errors = [
Expand All @@ -40,8 +38,12 @@ module.exports = ajv =>
];
passes = false;
}

if (!isCorrectAbsoluteOrRelativePath) {
// ?:[A-Za-z]:\\ - Windows absolute path
// \\\\ - Windows network absolute path
// \/ - Unix-like OS absolute path
const isCorrectAbsolutePath =
expected === /^(?:[A-Za-z]:(\\|\/)|\\\\|\/)/.test(data);
if (!isCorrectAbsolutePath) {
callback.errors = [getErrorFor(expected, data, schema)];
passes = false;
}
Expand Down

0 comments on commit d8c74b6

Please sign in to comment.