Skip to content

Commit

Permalink
fix within on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Nov 7, 2024
1 parent fb6b7fb commit 28ac2c1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
9 changes: 2 additions & 7 deletions src/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,8 @@ import {cwd} from "node:process";
import {fileURLToPath} from "node:url";
import {isEnoent} from "./error.js";

export function toOsPath(path: string): string {
return path.split(sep).join(op.sep);
}

export function fromOsPath(path: string): string {
return path.split(op.sep).join(sep);
}
export const toOsPath = sep === op.sep ? (path: string) => path : (path: string) => path.split(sep).join(op.sep);
export const fromOsPath = sep === op.sep ? (path: string) => path : (path: string) => path.split(op.sep).join(sep);

/**
* Returns the relative path from the current working directory to the given
Expand Down
5 changes: 4 additions & 1 deletion src/path.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {dirname, isAbsolute, join, normalize, relative, resolve} from "node:path/posix";
import op from "node:path";
import {dirname, join, normalize, relative, resolve} from "node:path/posix";

Check failure on line 2 in src/path.ts

View workflow job for this annotation

GitHub Actions / test (20, ubuntu-latest)

'normalize' is defined but never used.

Check failure on line 2 in src/path.ts

View workflow job for this annotation

GitHub Actions / test (20, ubuntu-latest)

'relative' is defined but never used.

Check failure on line 2 in src/path.ts

View workflow job for this annotation

GitHub Actions / test (20, ubuntu-latest)

'resolve' is defined but never used.

Check failure on line 2 in src/path.ts

View workflow job for this annotation

GitHub Actions / test (21, ubuntu-latest)

'normalize' is defined but never used.

Check failure on line 2 in src/path.ts

View workflow job for this annotation

GitHub Actions / test (21, ubuntu-latest)

'relative' is defined but never used.

Check failure on line 2 in src/path.ts

View workflow job for this annotation

GitHub Actions / test (21, ubuntu-latest)

'resolve' is defined but never used.
import {fromOsPath} from "./files.js";

Check failure on line 3 in src/path.ts

View workflow job for this annotation

GitHub Actions / test (20, ubuntu-latest)

'fromOsPath' is defined but never used.

Check failure on line 3 in src/path.ts

View workflow job for this annotation

GitHub Actions / test (21, ubuntu-latest)

'fromOsPath' is defined but never used.

/**
* Returns the normalized relative path from "/file/path/to/a" to
Expand Down Expand Up @@ -86,6 +88,7 @@ export function parseRelativeUrl(url: string): {pathname: string; search: string
}

export function within(root: string, path: string): boolean {
const {relative, normalize, resolve, isAbsolute} = op;
path = relative(normalize(resolve(root)), normalize(resolve(path)));
return !path.startsWith("..") && !isAbsolute(path);
}

0 comments on commit 28ac2c1

Please sign in to comment.