fix: optimized asar paths checks (#26024)

* fix: optimized asar paths checks

* fix: ensuring the linter is happy
This commit is contained in:
Fabio Spampinato 2020-10-26 03:19:35 +00:00 committed by GitHub
parent aa157c3f05
commit d4191c4a26
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -37,6 +37,8 @@ const getOrCreateArchive = (archivePath: string) => {
return newArchive; return newArchive;
}; };
const asarRe = /\.asar/i;
// Separate asar package's path from full path. // Separate asar package's path from full path.
const splitPath = (archivePathOrBuffer: string | Buffer) => { const splitPath = (archivePathOrBuffer: string | Buffer) => {
// Shortcut for disabled asar. // Shortcut for disabled asar.
@ -48,6 +50,7 @@ const splitPath = (archivePathOrBuffer: string | Buffer) => {
archivePath = archivePathOrBuffer.toString(); archivePath = archivePathOrBuffer.toString();
} }
if (typeof archivePath !== 'string') return { isAsar: <const>false }; if (typeof archivePath !== 'string') return { isAsar: <const>false };
if (!asarRe.test(archivePath)) return { isAsar: <const>false };
return asar.splitPath(path.normalize(archivePath)); return asar.splitPath(path.normalize(archivePath));
}; };