Last change
on this file since 6a80231 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
858 bytes
|
Rev | Line | |
---|
[6a3a178] | 1 | "use strict";
|
---|
| 2 |
|
---|
| 3 | var path = require("path");
|
---|
| 4 |
|
---|
| 5 | module.exports = function (thePath, potentialParent) {
|
---|
| 6 | // For inside-directory checking, we want to allow trailing slashes, so normalize.
|
---|
| 7 | thePath = stripTrailingSep(thePath);
|
---|
| 8 | potentialParent = stripTrailingSep(potentialParent);
|
---|
| 9 |
|
---|
| 10 | // Node treats only Windows as case-insensitive in its path module; we follow those conventions.
|
---|
| 11 | if (process.platform === "win32") {
|
---|
| 12 | thePath = thePath.toLowerCase();
|
---|
| 13 | potentialParent = potentialParent.toLowerCase();
|
---|
| 14 | }
|
---|
| 15 |
|
---|
| 16 | return thePath.lastIndexOf(potentialParent, 0) === 0 &&
|
---|
| 17 | (
|
---|
| 18 | thePath[potentialParent.length] === path.sep ||
|
---|
| 19 | thePath[potentialParent.length] === undefined
|
---|
| 20 | );
|
---|
| 21 | };
|
---|
| 22 |
|
---|
| 23 | function stripTrailingSep(thePath) {
|
---|
| 24 | if (thePath[thePath.length - 1] === path.sep) {
|
---|
| 25 | return thePath.slice(0, -1);
|
---|
| 26 | }
|
---|
| 27 | return thePath;
|
---|
| 28 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.