1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Desktop: Fix "open profile directory" shows a warning message (#10294)

This commit is contained in:
Henry Heino 2024-04-10 03:35:35 -07:00 committed by GitHub
parent 2ae08ff46e
commit 238683e36f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 5 deletions

View File

@ -362,7 +362,7 @@ export class Bridge {
if (await pathExists(fullPath)) {
const fileExtension = extname(fullPath);
const userAllowedExtension = this.extraAllowedOpenExtensions.includes(fileExtension);
if (userAllowedExtension || isSafeToOpen(fullPath)) {
if (userAllowedExtension || await isSafeToOpen(fullPath)) {
return shell.openPath(fullPath);
} else {
const allowOpenId = 2;

View File

@ -1,10 +1,10 @@
import { remove, writeFile } from 'fs-extra';
import { createTempDir } from '@joplin/lib/testing/test-utils';
import { join } from 'path';
import isUnsafeToOpen from './isSafeToOpen';
import isSafeToOpen from './isSafeToOpen';
describe('isUnsafeToOpen', () => {
describe('isSafeToOpen', () => {
test.each([
{ fileName: 'a.txt', expected: true },
{ fileName: 'a.json', expected: true },
@ -24,7 +24,7 @@ describe('isUnsafeToOpen', () => {
try {
const fullPath = join(tempDir, fileName);
await writeFile(fullPath, 'test');
expect(await isUnsafeToOpen(fullPath)).toBe(expected);
expect(await isSafeToOpen(fullPath)).toBe(expected);
} finally {
await remove(tempDir);
}

View File

@ -1,6 +1,8 @@
import { stat } from 'fs-extra';
import { extname } from 'path';
const isSafeToOpen = (path: string) => {
const isSafeToOpen = async (path: string) => {
// This is intended to fix an issue where some platforms would execute attachment
// files without confirmation depending on the file extension (e.g. .EXE). This is
// mostly for Windows.
@ -173,6 +175,11 @@ const isSafeToOpen = (path: string) => {
return true;
}
}
if (extname(path) === '' && (await stat(path)).isDirectory()) {
return true;
}
return false;
};