bare-url 2.5.4 → 2.5.5
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/README.md +4 -0
- package/index.d.ts +3 -0
- package/index.js +42 -18
- package/lib/errors.js +4 -0
- package/package.json +1 -1
- package/prebuilds/android-arm/bare-url.bare +0 -0
- package/prebuilds/android-arm64/bare-url.bare +0 -0
- package/prebuilds/android-ia32/bare-url.bare +0 -0
- package/prebuilds/android-x64/bare-url.bare +0 -0
- package/prebuilds/darwin-arm64/bare-url.bare +0 -0
- package/prebuilds/darwin-x64/bare-url.bare +0 -0
- package/prebuilds/ios-arm64/bare-url.bare +0 -0
- package/prebuilds/ios-arm64-simulator/bare-url.bare +0 -0
- package/prebuilds/ios-x64-simulator/bare-url.bare +0 -0
- package/prebuilds/linux-arm64/bare-url.bare +0 -0
- package/prebuilds/linux-x64/bare-url.bare +0 -0
- package/prebuilds/win32-arm64/bare-url.bare +0 -0
- package/prebuilds/win32-x64/bare-url.bare +0 -0
package/README.md
CHANGED
|
@@ -28,6 +28,10 @@ require('bare-url/global')
|
|
|
28
28
|
|
|
29
29
|
See the [`bare-url` reference](https://docs.pears.com/reference/bare/modules/bare-url).
|
|
30
30
|
|
|
31
|
+
## Threat model
|
|
32
|
+
|
|
33
|
+
`bare-url` is one of the addons Bare compiles into its binary, so it inherits [Bare's threat model](https://github.com/holepunchto/bare/blob/main/docs/threat-model.md). See [`docs/threat-model.md`](docs/threat-model.md) for where this addon sits in it.
|
|
34
|
+
|
|
31
35
|
## License
|
|
32
36
|
|
|
33
37
|
Apache-2.0
|
package/index.d.ts
CHANGED
|
@@ -87,6 +87,9 @@ declare namespace URL {
|
|
|
87
87
|
/**
|
|
88
88
|
* Convert a platform-specific file path to a `file:` URL.
|
|
89
89
|
* @param pathname - The platform-specific file path to convert.
|
|
90
|
+
* @throws {INVALID_ARG_VALUE} (Windows) the path is a UNC path with an empty server name or
|
|
91
|
+
* no resource path.
|
|
92
|
+
* @throws {INVALID_URL} the path does not form a valid `file:` URL.
|
|
90
93
|
*/
|
|
91
94
|
export function pathToFileURL(pathname: string): URL
|
|
92
95
|
|
package/index.js
CHANGED
|
@@ -494,6 +494,26 @@ function encodePath(value) {
|
|
|
494
494
|
return value.replace(pathDelimiterAll, (match) => escapes[match])
|
|
495
495
|
}
|
|
496
496
|
|
|
497
|
+
function encodeFilePath(value) {
|
|
498
|
+
// Paths hardly ever contain any of these, so one pass to rule them out is
|
|
499
|
+
// cheaper than the six or seven replacements it stands in for.
|
|
500
|
+
if (!reserved.test(value)) return value
|
|
501
|
+
|
|
502
|
+
value = value
|
|
503
|
+
.replaceAll('%', '%25') // Must be first
|
|
504
|
+
.replaceAll('#', '%23')
|
|
505
|
+
.replaceAll('?', '%3f')
|
|
506
|
+
.replaceAll('\n', '%0a')
|
|
507
|
+
.replaceAll('\r', '%0d')
|
|
508
|
+
.replaceAll('\t', '%09')
|
|
509
|
+
|
|
510
|
+
if (!isWindows) {
|
|
511
|
+
value = value.replaceAll('\\', '%5c')
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
return value
|
|
515
|
+
}
|
|
516
|
+
|
|
497
517
|
function encodeQuery(value) {
|
|
498
518
|
if (value.indexOf('#') === -1) return value
|
|
499
519
|
|
|
@@ -600,7 +620,27 @@ exports.fileURLToPath = function fileURLToPath(url) {
|
|
|
600
620
|
}
|
|
601
621
|
|
|
602
622
|
exports.pathToFileURL = function pathToFileURL(pathname) {
|
|
603
|
-
|
|
623
|
+
const isUNC = isWindows && pathname.startsWith('\\\\')
|
|
624
|
+
|
|
625
|
+
let resolved = isUNC ? pathname : path.resolve(pathname)
|
|
626
|
+
|
|
627
|
+
if (isUNC || (isWindows && resolved.startsWith('\\\\'))) {
|
|
628
|
+
// https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation
|
|
629
|
+
const hostStart = resolved.startsWith('\\\\?\\UNC\\') ? 8 : 2
|
|
630
|
+
const hostEnd = resolved.indexOf('\\', hostStart)
|
|
631
|
+
|
|
632
|
+
if (hostEnd === -1) {
|
|
633
|
+
throw errors.INVALID_ARG_VALUE('Missing UNC resource path')
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
if (hostEnd === 2) {
|
|
637
|
+
throw errors.INVALID_ARG_VALUE('Empty UNC servername')
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
const hostname = truncateHost('file', resolved.slice(hostStart, hostEnd))
|
|
641
|
+
|
|
642
|
+
return new URL('file://' + hostname + encodeFilePath(resolved.slice(hostEnd)))
|
|
643
|
+
}
|
|
604
644
|
|
|
605
645
|
if (pathname[pathname.length - 1] === '/') {
|
|
606
646
|
resolved += '/'
|
|
@@ -608,23 +648,7 @@ exports.pathToFileURL = function pathToFileURL(pathname) {
|
|
|
608
648
|
resolved += '\\'
|
|
609
649
|
}
|
|
610
650
|
|
|
611
|
-
|
|
612
|
-
// cheaper than the six or seven replacements it stands in for.
|
|
613
|
-
if (reserved.test(resolved)) {
|
|
614
|
-
resolved = resolved
|
|
615
|
-
.replaceAll('%', '%25') // Must be first
|
|
616
|
-
.replaceAll('#', '%23')
|
|
617
|
-
.replaceAll('?', '%3f')
|
|
618
|
-
.replaceAll('\n', '%0a')
|
|
619
|
-
.replaceAll('\r', '%0d')
|
|
620
|
-
.replaceAll('\t', '%09')
|
|
621
|
-
|
|
622
|
-
if (!isWindows) {
|
|
623
|
-
resolved = resolved.replaceAll('\\', '%5c')
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
return new URL('file:' + resolved)
|
|
651
|
+
return new URL('file:' + encodeFilePath(resolved))
|
|
628
652
|
}
|
|
629
653
|
|
|
630
654
|
exports.format = function format(parts) {
|
package/lib/errors.js
CHANGED
|
@@ -30,4 +30,8 @@ module.exports = class URLError extends Error {
|
|
|
30
30
|
static INVALID_FILE_URL_PATH(msg = 'Invalid file: URL path') {
|
|
31
31
|
return new URLError(msg, URLError.INVALID_FILE_URL_PATH)
|
|
32
32
|
}
|
|
33
|
+
|
|
34
|
+
static INVALID_ARG_VALUE(msg = 'Invalid argument value') {
|
|
35
|
+
return new URLError(msg, URLError.INVALID_ARG_VALUE)
|
|
36
|
+
}
|
|
33
37
|
}
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|