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:
parent
2ae08ff46e
commit
238683e36f
@ -362,7 +362,7 @@ export class Bridge {
|
|||||||
if (await pathExists(fullPath)) {
|
if (await pathExists(fullPath)) {
|
||||||
const fileExtension = extname(fullPath);
|
const fileExtension = extname(fullPath);
|
||||||
const userAllowedExtension = this.extraAllowedOpenExtensions.includes(fileExtension);
|
const userAllowedExtension = this.extraAllowedOpenExtensions.includes(fileExtension);
|
||||||
if (userAllowedExtension || isSafeToOpen(fullPath)) {
|
if (userAllowedExtension || await isSafeToOpen(fullPath)) {
|
||||||
return shell.openPath(fullPath);
|
return shell.openPath(fullPath);
|
||||||
} else {
|
} else {
|
||||||
const allowOpenId = 2;
|
const allowOpenId = 2;
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import { remove, writeFile } from 'fs-extra';
|
import { remove, writeFile } from 'fs-extra';
|
||||||
import { createTempDir } from '@joplin/lib/testing/test-utils';
|
import { createTempDir } from '@joplin/lib/testing/test-utils';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import isUnsafeToOpen from './isSafeToOpen';
|
import isSafeToOpen from './isSafeToOpen';
|
||||||
|
|
||||||
|
|
||||||
describe('isUnsafeToOpen', () => {
|
describe('isSafeToOpen', () => {
|
||||||
test.each([
|
test.each([
|
||||||
{ fileName: 'a.txt', expected: true },
|
{ fileName: 'a.txt', expected: true },
|
||||||
{ fileName: 'a.json', expected: true },
|
{ fileName: 'a.json', expected: true },
|
||||||
@ -24,7 +24,7 @@ describe('isUnsafeToOpen', () => {
|
|||||||
try {
|
try {
|
||||||
const fullPath = join(tempDir, fileName);
|
const fullPath = join(tempDir, fileName);
|
||||||
await writeFile(fullPath, 'test');
|
await writeFile(fullPath, 'test');
|
||||||
expect(await isUnsafeToOpen(fullPath)).toBe(expected);
|
expect(await isSafeToOpen(fullPath)).toBe(expected);
|
||||||
} finally {
|
} finally {
|
||||||
await remove(tempDir);
|
await remove(tempDir);
|
||||||
}
|
}
|
||||||
|
@ -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
|
// 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
|
// files without confirmation depending on the file extension (e.g. .EXE). This is
|
||||||
// mostly for Windows.
|
// mostly for Windows.
|
||||||
@ -173,6 +175,11 @@ const isSafeToOpen = (path: string) => {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (extname(path) === '' && (await stat(path)).isDirectory()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user