Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ms-cloudpack/path-string-parsing

Package Overview
Dependencies
Maintainers
3
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ms-cloudpack/path-string-parsing - npm Package Compare versions

Comparing version 1.2.0 to 1.2.1

5

lib/normalizeRelativePath.d.ts
/**
* Normalize a path:
* - If it's empty, undefined, or `'.'`, return `'.'`.
* - If it's empty, undefined, or `.`, return `.`.
* - If it's relative, normalize slashes and ensure it starts with `./`.
* - If it starts with `/`, add a leading `.` (this is an absolute path but is sometimes treated
* as package-relative)
* - If it's an absolute Windows path (starts with a drive letter), throw an error.
* - If it's absolute, throw an error (since this likely indicates a bug in the calling code).

@@ -6,0 +9,0 @@ *

29

lib/normalizeRelativePath.js
import { slash } from './slash.js';
/**
* Normalize a path:
* - If it's empty, undefined, or `'.'`, return `'.'`.
* - If it's empty, undefined, or `.`, return `.`.
* - If it's relative, normalize slashes and ensure it starts with `./`.
* - If it starts with `/`, add a leading `.` (this is an absolute path but is sometimes treated
* as package-relative)
* - If it's an absolute Windows path (starts with a drive letter), throw an error.
* - If it's absolute, throw an error (since this likely indicates a bug in the calling code).

@@ -14,12 +17,22 @@ *

}
// Throw if the path is absolute.
// NOTE: Don't use the `path` module because this function is used by `parseImportString`, which
// is used in the browser by the overlay.
if (originalPath[0] === '/' || /^[a-zA-Z]:[\\/]/.test(originalPath)) {
throw new Error(`Expected a relative path, but received an absolute path: ${originalPath}`);
// Throw on an absolute Windows path: this is definitely absolute regardless of the context it
// came from, and if the calling code attempts to join it to another path as if it was relative,
// that will have bad results. It's more likely on Windows that we could unintentionally end up
// with an absolute path since there's no way to do relative paths across drive letters
// (path.relative() will return an absolute path), so we throw here to make it clear that
// Cloudpack needs to have specific handling for any cases where that might be possible.
if (/^[a-zA-Z]:[\\/]/.test(originalPath)) {
throw new Error(`Received an absolute path where a relative path was expected: ${originalPath}.\n` +
'This indicates a bug in Cloudpack, likely due to calling path.relative() with two Windows paths ' +
'on different drives (which returns an absolute path) and then assuming the result is relative.');
}
// Ensure we have the right slashes.
originalPath = slash(originalPath);
return originalPath.startsWith('./') ? originalPath : `./${originalPath}`;
const normalizedPath = slash(originalPath);
if (normalizedPath[0] === '/') {
// Technically a path starting with / is absolute, but it's possible that package.json
// entry points like "main" could also use a leading slash to indicate the package root.
return '.' + normalizedPath;
}
return normalizedPath.startsWith('./') ? normalizedPath : `./${normalizedPath}`;
}
//# sourceMappingURL=normalizeRelativePath.js.map
{
"name": "@ms-cloudpack/path-string-parsing",
"version": "1.2.0",
"version": "1.2.1",
"description": "Common path-related string parsing utilities for Cloudpack",

@@ -5,0 +5,0 @@ "license": "MIT",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc