improve: add safe path join

This commit is contained in:
charlie
2022-08-17 12:27:12 +08:00
committed by Andelf
parent b6caba48d8
commit 1a6379f118
3 changed files with 21 additions and 3 deletions

View File

@@ -310,5 +310,18 @@ export const nodePath = Object.assign({}, path, {
extname (input) {
input = toPosixPath(input)
return path.extname(input)
},
join (input, ...paths) {
let orURI = null
try {
orURI = new URL(input)
input = orURI.pathname
} catch (_e) {}
input = path.join(input, ...paths)
return (orURI ? (orURI.protocol + '//') : '') + input
}
})