Skip to content

Commit

Permalink
Desktop: Fix "open profile directory" shows a warning message (#10294)
Browse files Browse the repository at this point in the history
  • Loading branch information
personalizedrefrigerator committed Apr 10, 2024
1 parent 2ae08ff commit 238683e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/app-desktop/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions packages/app-desktop/utils/isSafeToOpen.test.ts
Original file line number Diff line number Diff line change
@@ -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 },
Expand All @@ -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);
}
Expand Down
9 changes: 8 additions & 1 deletion packages/app-desktop/utils/isSafeToOpen.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -173,6 +175,11 @@ const isSafeToOpen = (path: string) => {
return true;
}
}

if (extname(path) === '' && (await stat(path)).isDirectory()) {
return true;
}

return false;
};

Expand Down

0 comments on commit 238683e

Please sign in to comment.