mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-07-10 09:24:56 +02:00
Fix incorrect subpath checks
This commit is contained in:
parent
49403771c9
commit
976ae502bb
2 changed files with 15 additions and 3 deletions
|
@ -19,6 +19,18 @@ const filePathToPOSIX = (path) => {
|
|||
}
|
||||
module.exports.filePathToPOSIX = filePathToPOSIX
|
||||
|
||||
function isSameOrSubPath(parentPath, childPath) {
|
||||
parentPath = filePathToPOSIX(parentPath)
|
||||
childPath = filePathToPOSIX(childPath)
|
||||
if (parentPath === childPath) return true
|
||||
const relativePath = Path.relative(parentPath, childPath)
|
||||
return (
|
||||
relativePath === '' // Same path (e.g. parentPath = '/a/b/', childPath = '/a/b')
|
||||
|| !relativePath.startsWith('..') && !Path.isAbsolute(relativePath) // Sub path
|
||||
)
|
||||
}
|
||||
module.exports.isSameOrSubPath = isSameOrSubPath
|
||||
|
||||
async function getFileStat(path) {
|
||||
try {
|
||||
var stat = await fs.stat(path)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue