Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading