@nxworker/workspace
Version:
Nx plugin providing generators for managing workspace files, including the move-file generator for safely moving files between projects while updating all imports
27 lines (26 loc) • 921 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "sanitizePath", {
enumerable: true,
get: function() {
return sanitizePath;
}
});
const _devkit = require("@nx/devkit");
const _nodepath = require("node:path");
function sanitizePath(filePath) {
// Convert backslashes to forward slashes for Windows compatibility
let normalized = (0, _devkit.normalizePath)(filePath);
// Remove leading slash
normalized = normalized.replace(/^\//, '');
// Normalize the path to resolve '..' and '.'
normalized = _nodepath.posix.normalize(normalized);
// Ensure the path doesn't try to escape using '..'
if (normalized.startsWith('..') || normalized.includes('/../')) {
throw new Error(`Invalid path: path traversal detected in "${filePath}"`);
}
return normalized;
}
//# sourceMappingURL=sanitize-path.js.map