2021-08-02 11:31:59 -04:00
|
|
|
"use strict";
|
|
|
|
const path = require("path");
|
2017-07-29 13:23:33 -04:00
|
|
|
|
|
|
|
module.exports = outsideDirectory;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if a file is outside of a directory.
|
|
|
|
*
|
|
|
|
* @param {String} file Path to the file.
|
|
|
|
* @param {String} directory Path to the directory.
|
|
|
|
* @returns {Boolean} Whether the file is outside of the directory.
|
2017-12-28 14:34:30 -05:00
|
|
|
*
|
|
|
|
* @private
|
2017-07-29 13:23:33 -04:00
|
|
|
*/
|
|
|
|
function outsideDirectory(file, directory) {
|
2021-08-02 11:31:59 -04:00
|
|
|
return path.relative(directory, file).indexOf("..") === 0;
|
2017-07-29 13:23:33 -04:00
|
|
|
}
|