pax_global_header00006660000000000000000000000064127651142030014513gustar00rootroot0000000000000052 comment=05a9bf7c5e008505539e14e96c4d2fc8b2c6d058 path-is-inside-1.0.2/000077500000000000000000000000001276511420300143315ustar00rootroot00000000000000path-is-inside-1.0.2/.gitignore000066400000000000000000000000361276511420300163200ustar00rootroot00000000000000/node_modules/ /npm-debug.log path-is-inside-1.0.2/.jshintrc000066400000000000000000000005661276511420300161650ustar00rootroot00000000000000{ "bitwise": true, "camelcase": true, "curly": true, "eqeqeq": true, "globalstrict": true, "immed": true, "indent": 4, "latedef": "nofunc", "maxlen": 120, "newcap": true, "noarg": true, "node": true, "nonew": true, "quotmark": "double", "trailing": true, "undef": true, "unused": true, "white": true } path-is-inside-1.0.2/.travis.yml000066400000000000000000000001111276511420300164330ustar00rootroot00000000000000language: node_js node_js: - "0.10" script: npm run lint && npm test path-is-inside-1.0.2/LICENSE.txt000066400000000000000000000035351276511420300161620ustar00rootroot00000000000000Dual licensed under WTFPL and MIT: --- Copyright © 2013–2016 Domenic Denicola This work is free. You can redistribute it and/or modify it under the terms of the Do What The Fuck You Want To Public License, Version 2, as published by Sam Hocevar. See below for more details. DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE Version 2, December 2004 Copyright (C) 2004 Sam Hocevar Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed. DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. You just DO WHAT THE FUCK YOU WANT TO. --- The MIT License (MIT) Copyright © 2013–2016 Domenic Denicola Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. path-is-inside-1.0.2/README.md000066400000000000000000000030771276511420300156170ustar00rootroot00000000000000# Is This Path Inside This Other Path? It turns out this question isn't trivial to answer using Node's built-in path APIs. A naive `indexOf`-based solution will fail sometimes on Windows, which is case-insensitive (see e.g. [isaacs/npm#4214][]). You might then think to be clever with `path.resolve`, but you have to be careful to account for situations whether the paths have different drive letters, or else you'll cause bugs like [isaacs/npm#4313][]. And let's not even get started on trailing slashes. The **path-is-inside** package will give you a robust, cross-platform way of detecting whether a given path is inside another path. ## Usage Pretty simple. First the path being tested; then the potential parent. Like so: ```js var pathIsInside = require("path-is-inside"); pathIsInside("/x/y/z", "/x/y") // true pathIsInside("/x/y", "/x/y/z") // false ``` Paths are considered to be inside themselves: ```js pathIsInside("/x/y", "/x/y"); // true ``` ## OS-Specific Behavior Like Node's built-in path module, path-is-inside treats all file paths on Windows as case-insensitive, whereas it treats all file paths on *-nix operating systems as case-sensitive. Keep this in mind especially when working on a Mac, where, despite Node's defaults, the OS usually treats paths case-insensitively. In practice, this means: ```js // On Windows pathIsInside("C:\\X\\Y\\Z", "C:\\x\\y") // true // On *-nix, including Mac OS X pathIsInside("/X/Y/Z", "/x/y") // false ``` [isaacs/npm#4214]: https://github.com/isaacs/npm/pull/4214 [isaacs/npm#4313]: https://github.com/isaacs/npm/issues/4313 path-is-inside-1.0.2/lib/000077500000000000000000000000001276511420300150775ustar00rootroot00000000000000path-is-inside-1.0.2/lib/path-is-inside.js000066400000000000000000000015321276511420300202540ustar00rootroot00000000000000"use strict"; var path = require("path"); module.exports = function (thePath, potentialParent) { // For inside-directory checking, we want to allow trailing slashes, so normalize. thePath = stripTrailingSep(thePath); potentialParent = stripTrailingSep(potentialParent); // Node treats only Windows as case-insensitive in its path module; we follow those conventions. if (process.platform === "win32") { thePath = thePath.toLowerCase(); potentialParent = potentialParent.toLowerCase(); } return thePath.lastIndexOf(potentialParent, 0) === 0 && ( thePath[potentialParent.length] === path.sep || thePath[potentialParent.length] === undefined ); }; function stripTrailingSep(thePath) { if (thePath[thePath.length - 1] === path.sep) { return thePath.slice(0, -1); } return thePath; } path-is-inside-1.0.2/package.json000066400000000000000000000011051276511420300166140ustar00rootroot00000000000000{ "name": "path-is-inside", "description": "Tests whether one path is inside another path", "keywords": ["path", "directory", "folder", "inside", "relative"], "version": "1.0.2", "author": "Domenic Denicola (https://domenic.me)", "license": "(WTFPL OR MIT)", "repository": "domenic/path-is-inside", "main": "lib/path-is-inside.js", "files": [ "lib" ], "scripts": { "test": "mocha", "lint": "jshint lib" }, "devDependencies": { "jshint": "~2.3.0", "mocha": "~1.15.1" } } path-is-inside-1.0.2/test/000077500000000000000000000000001276511420300153105ustar00rootroot00000000000000path-is-inside-1.0.2/test/tests.js000066400000000000000000000070251276511420300170140ustar00rootroot00000000000000"use strict"; var assert = require("assert"); var path = require("path"); var pathIsInside = require(".."); // The test data is in the form [thePath, potentialParent, expectedResult]. // For *nix-derived operating systems, we will test all these, plus all permutations with `/` appended, which should // give the same result. var nixTests = [ ["/x/y/z", "/a/b/c", false], ["/x/y/z", "/x/y", true], ["/x/y/z", "/x/y/z", true], ["/x/y/z", "/x/y/z/w", false], ["/x/y/z", "/x/y/w", false], ["/x/y", "/x/yy", false], ["/x/yy", "/x/y", false], ["/X/y/z", "/x/y", false], ["/x/Y/z", "/x/y/z", false] ]; // For Windows, we will test all these, plus all permutations with `\` appended, plus all permutations with the drive // letter lowercased. var windowsTests = [ ["C:\\x\\y\\z", "C:\\a\\b\\c", false], ["C:\\x\\y\\z", "C:\\x\\y", true], ["C:\\x\\y\\z", "C:\\x\\y\\z", true], ["C:\\x\\y\\z", "C:\\x\\y\\z\\w", false], ["C:\\x\\y\\z", "C:\\x\\y\\w", false], ["C:\\x\\y", "C:\\x\\yy", false], ["C:\\x\\yy", "C:\\x\\y", false], ["C:\\x\\y\\z", "D:\\x\\y\\z", false], ["C:\\x\\y\\z", "D:\\x\\y\\z\\w", false] ]; describe("*-nix style paths", function () { describe("process.platform = \"darwin\"", function () { before(function () { Object.defineProperty(process, "platform", { value: "darwin" }); Object.defineProperty(path, "sep", { value: "/" }); }); nixTests.forEach(function (data) { runCase(data); runCase([data[0], data[1] + "/", data[2]]); runCase([data[0] + "/", data[1], data[2]]); runCase([data[0] + "/", data[1] + "/", data[2]]); }); }); describe("process.platform = \"linux\"", function () { before(function () { Object.defineProperty(process, "platform", { value: "linux" }); Object.defineProperty(path, "sep", { value: "/" }); }); nixTests.forEach(function (data) { runCase(data); runCase([data[0], data[1] + "/", data[2]]); runCase([data[0] + "/", data[1], data[2]]); runCase([data[0] + "/", data[1] + "/", data[2]]); }); }); }); describe("Windows-style paths", function () { before(function () { Object.defineProperty(process, "platform", { value: "win32" }); Object.defineProperty(path, "sep", { value: "\\" }); }); describe("Uppercase drive letters", function () { windowsTests.forEach(runCases); }); describe("Uppercase, then lowercase, drive letters", function () { windowsTests.forEach(function (data) { runCases([data[0], data[1].toLowerCase(), data[2]]); }); }); describe("Lowercase, then uppercase, drive letters", function () { windowsTests.forEach(function (data) { runCases([data[0], data[1].toLowerCase(), data[2]]); }); }); describe("Lowercase drive letters", function () { windowsTests.forEach(function (data) { runCases([data[0].toLowerCase(), data[1].toLowerCase(), data[2]]); }); }); function runCases(data) { runCase(data); runCase([data[0], data[1] + "\\", data[2]]); runCase([data[0] + "\\", data[1], data[2]]); runCase([data[0] + "\\", data[1] + "\\", data[2]]); } }); function runCase(data) { specify("pathIsInside(\"" + data[0] + "\", \"" + data[1] + "\") should be " + data[2], function () { assert.strictEqual(pathIsInside(data[0], data[1]), data[2]); }); }