Skip to content

Commit

Permalink
fix: windows根目录
Browse files Browse the repository at this point in the history
  • Loading branch information
Eavid committed Sep 9, 2023
1 parent 90cc493 commit ca7a75f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/util/file_tool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ describe.each(eachArg)("upSearch", function ({ cases, name }) {
});
describe("upSearch-window特殊", function () {
it("/", function () {
const res = upSearchAll("/");
const res = upSearchAll("/", undefined, win32);
expect(res).toHaveLength(1);
expect(res[0]).toMatch(/^((\w:)|\\)$/); //window: "C:" posix: "\"
});
it("/b", function () {
const res = upSearchAll("/b");
const res = upSearchAll("/b", undefined, win32);
expect(res).toHaveLength(2);
expect(res[0], "0").toMatch(/^((\w:)?\\b)$/); //window: "C:\b" posix: "\b"
expect(res[1], "1").toMatch(/^((\w:)|\\)$/); //window: "C:" posix: "\"
Expand Down
5 changes: 3 additions & 2 deletions src/util/file_tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ export function* upSearch(checkPath: string, first = true, nodePath = Path) {
let { root, dir, base } = nodePath.parse(nodePath.resolve(checkPath));
const sep = nodePath.sep;
if (base === "") {
if (sep === "\\" && dir.endsWith(sep)) checkPath = dir.slice(0, -1);
else checkPath = dir;
if (Path.sep === "\\" && dir.endsWith(Path.sep)) {
checkPath = dir.slice(0, -1); //windows 特殊
} else checkPath = dir;
} else checkPath = dir === root ? root + base : dir + sep + base;

if (first) yield checkPath;
Expand Down

0 comments on commit ca7a75f

Please sign in to comment.