@nomicfoundation/hardhat-utils 4.1.3 → 4.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/src/path.d.ts +3 -2
- package/dist/src/path.d.ts.map +1 -1
- package/dist/src/path.js +13 -2
- package/dist/src/path.js.map +1 -1
- package/package.json +1 -1
- package/src/path.ts +18 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @nomicfoundation/hardhat-utils
|
|
2
2
|
|
|
3
|
+
## 4.1.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#8402](https://github.com/NomicFoundation/hardhat/pull/8402) [`afa9bc4`](https://github.com/NomicFoundation/hardhat/commit/afa9bc44e14563c1fd77440228ef6fbc785774b4) Thanks [@flag4table](https://github.com/flag4table)! - Make `sanitizeFilename` avoid Windows reserved device names while preserving filename extensions.
|
|
8
|
+
|
|
3
9
|
## 4.1.3
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/dist/src/path.d.ts
CHANGED
|
@@ -29,8 +29,9 @@ export declare function shortenPath(absolutePath: string): string;
|
|
|
29
29
|
*
|
|
30
30
|
* Strips characters that are reserved on at least one of those platforms
|
|
31
31
|
* (`<>:"/\|?*` and ASCII control chars), trims trailing dots and whitespace
|
|
32
|
-
* (Windows silently strips them on write),
|
|
33
|
-
* result is empty or one of the
|
|
32
|
+
* (Windows silently strips them on write), avoids Windows reserved device
|
|
33
|
+
* names, and falls back to `_` if the result is empty or one of the
|
|
34
|
+
* path-traversal literals `.` / `..`.
|
|
34
35
|
*
|
|
35
36
|
* @param name The string to sanitize.
|
|
36
37
|
* @returns A non-empty filename-safe string.
|
package/dist/src/path.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../../src/path.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../../src/path.ts"],"names":[],"mappings":"AAKA;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAMpE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAqBxD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAqBrD"}
|
package/dist/src/path.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
+
const WINDOWS_RESERVED_FILENAME_PATTERN = /^(con|prn|aux|nul|com[1-9]|lpt[1-9])(\..*)?$/i;
|
|
2
3
|
/**
|
|
3
4
|
* Resolves a user-provided path into an absolute path.
|
|
4
5
|
*
|
|
@@ -50,8 +51,9 @@ export function shortenPath(absolutePath) {
|
|
|
50
51
|
*
|
|
51
52
|
* Strips characters that are reserved on at least one of those platforms
|
|
52
53
|
* (`<>:"/\|?*` and ASCII control chars), trims trailing dots and whitespace
|
|
53
|
-
* (Windows silently strips them on write),
|
|
54
|
-
* result is empty or one of the
|
|
54
|
+
* (Windows silently strips them on write), avoids Windows reserved device
|
|
55
|
+
* names, and falls back to `_` if the result is empty or one of the
|
|
56
|
+
* path-traversal literals `.` / `..`.
|
|
55
57
|
*
|
|
56
58
|
* @param name The string to sanitize.
|
|
57
59
|
* @returns A non-empty filename-safe string.
|
|
@@ -62,6 +64,15 @@ export function sanitizeFilename(name) {
|
|
|
62
64
|
if (result === "" || result === "." || result === "..") {
|
|
63
65
|
result = "_";
|
|
64
66
|
}
|
|
67
|
+
if (WINDOWS_RESERVED_FILENAME_PATTERN.test(result)) {
|
|
68
|
+
const extensionIndex = result.indexOf(".");
|
|
69
|
+
if (extensionIndex === -1) {
|
|
70
|
+
result = `${result}_`;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
result = `${result.slice(0, extensionIndex)}_${result.slice(extensionIndex)}`;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
65
76
|
return result;
|
|
66
77
|
}
|
|
67
78
|
//# sourceMappingURL=path.js.map
|
package/dist/src/path.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path.js","sourceRoot":"","sources":["../../src/path.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B;;;;;;;;;GASG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY,EAAE,MAAc;IAC1D,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QAC5B,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AACpC,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,WAAW,CAAC,YAAoB;IAC9C,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAC1B,IAAI,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;IAEpD,IAAI,YAAY,KAAK,IAAI,EAAE,CAAC;QAC1B,OAAO,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC;IACzB,CAAC;IAED,IACE,CAAC,YAAY,CAAC,UAAU,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC;QACzC,CAAC,YAAY,CAAC,UAAU,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;QACxC,CAAC,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,EAC9B,CAAC;QACD,YAAY,GAAG,GAAG,GAAG,IAAI,CAAC,GAAG,GAAG,YAAY,CAAC;IAC/C,CAAC;IAED,IAAI,YAAY,CAAC,MAAM,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC;QAC9C,OA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,CAAC,IAAY;IAC3C,IAAI,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,4BAA4B,EAAE,EAAE,CAAC,CAAC;IAC5D,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IAEvC,IAAI,MAAM,KAAK,EAAE,IAAI,MAAM,KAAK,GAAG,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QACvD,MAAM,GAAG,GAAG,CAAC;IACf,CAAC;IAED,IAAI,iCAAiC,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QACnD,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAE3C,IAAI,cAAc,KAAK,CAAC,CAAC,EAAE,CAAC;YAC1B,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC;QACxB,CAAC;aAAM,CAAC;YACN,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,cAAc,CAAC,IAAI,MAAM,CAAC,KAAK,CACzD,cAAc,CACf,EAAE,CAAC;QACN,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
package/src/path.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
|
|
3
|
+
const WINDOWS_RESERVED_FILENAME_PATTERN =
|
|
4
|
+
/^(con|prn|aux|nul|com[1-9]|lpt[1-9])(\..*)?$/i;
|
|
5
|
+
|
|
3
6
|
/**
|
|
4
7
|
* Resolves a user-provided path into an absolute path.
|
|
5
8
|
*
|
|
@@ -60,8 +63,9 @@ export function shortenPath(absolutePath: string): string {
|
|
|
60
63
|
*
|
|
61
64
|
* Strips characters that are reserved on at least one of those platforms
|
|
62
65
|
* (`<>:"/\|?*` and ASCII control chars), trims trailing dots and whitespace
|
|
63
|
-
* (Windows silently strips them on write),
|
|
64
|
-
* result is empty or one of the
|
|
66
|
+
* (Windows silently strips them on write), avoids Windows reserved device
|
|
67
|
+
* names, and falls back to `_` if the result is empty or one of the
|
|
68
|
+
* path-traversal literals `.` / `..`.
|
|
65
69
|
*
|
|
66
70
|
* @param name The string to sanitize.
|
|
67
71
|
* @returns A non-empty filename-safe string.
|
|
@@ -74,5 +78,17 @@ export function sanitizeFilename(name: string): string {
|
|
|
74
78
|
result = "_";
|
|
75
79
|
}
|
|
76
80
|
|
|
81
|
+
if (WINDOWS_RESERVED_FILENAME_PATTERN.test(result)) {
|
|
82
|
+
const extensionIndex = result.indexOf(".");
|
|
83
|
+
|
|
84
|
+
if (extensionIndex === -1) {
|
|
85
|
+
result = `${result}_`;
|
|
86
|
+
} else {
|
|
87
|
+
result = `${result.slice(0, extensionIndex)}_${result.slice(
|
|
88
|
+
extensionIndex,
|
|
89
|
+
)}`;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
77
93
|
return result;
|
|
78
94
|
}
|