Skip to content

Commit 73bc803

Browse files
committed
fix #521
1 parent cade0a4 commit 73bc803

File tree

3 files changed

+48
-20
lines changed

3 files changed

+48
-20
lines changed

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
blank_issues_enabled: false
22
contact_links:
3-
- name: "Meta Bind thead on the official Obsidian Discord server"
4-
url: "https://discord.com/channels/686053708261228577/1286803892549713921"
5-
about: "Please ask your questions on the official Obsidian Discord server in the \"Meta Bind ans JS Engine\" thread."
6-
- name: "Discussions"
7-
url: "https://github.com/mProjectsCode/obsidian-meta-bind-plugin/discussions"
8-
about: "If you don't want to join the official Obsidian Discord server, you can use the Discussions tab of this repository to ask your questions."
3+
- name: 'Meta Bind thead on the official Obsidian Discord server'
4+
url: 'https://discord.com/channels/686053708261228577/1286803892549713921'
5+
about: 'Please ask your questions on the official Obsidian Discord server in the "Meta Bind ans JS Engine" thread.'
6+
- name: 'Discussions'
7+
url: 'https://github.com/mProjectsCode/obsidian-meta-bind-plugin/discussions'
8+
about: "If you don't want to join the official Obsidian Discord server, you can use the Discussions tab of this repository to ask your questions."

packages/core/src/utils/Utils.ts

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -324,21 +324,42 @@ export function getFolderPathFromFilePath(filePath: string): string {
324324
* Joins the given paths together without duplicate slashes.
325325
*/
326326
export function joinPath(...paths: string[]): string {
327-
let result = paths[0];
327+
if (paths.length === 0) {
328+
return '/';
329+
}
330+
if (paths.length === 1) {
331+
return cleanPath(paths[0]);
332+
}
333+
334+
let result = paths[0].startsWith('/') ? paths[0].substring(1) : paths[0];
328335
for (let i = 1; i < paths.length; i++) {
336+
if (paths[i] === '' || paths[i] === '/') {
337+
continue;
338+
}
339+
329340
const endsWithSlash = result.endsWith('/');
330341
const startsWithSlash = paths[i].startsWith('/');
331342

332343
if (endsWithSlash && startsWithSlash) {
333-
result = result.substring(0, result.length - 1);
344+
result += paths[i].substring(1);
334345
} else if (!endsWithSlash && !startsWithSlash) {
335-
result += '/';
346+
result += '/' + paths[i];
347+
} else {
348+
result += paths[i];
336349
}
337-
338-
result += paths[i];
339350
}
340351

341-
return result;
352+
return cleanPath(result);
353+
}
354+
355+
export function cleanPath(path: string): string {
356+
if (path.startsWith('/')) {
357+
path = path.substring(1);
358+
}
359+
if (path.endsWith('/')) {
360+
path = path.substring(0, path.length - 1);
361+
}
362+
return path === '' ? '/' : path;
342363
}
343364

344365
/**

tests/utils/Utils.test.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -245,22 +245,29 @@ describe('utils', () => {
245245

246246
test('should handle single path correctly', () => {
247247
expect(joinPath('path')).toBe('path');
248-
expect(joinPath('/path')).toBe('/path');
249-
expect(joinPath('path/')).toBe('path/');
248+
expect(joinPath('/path')).toBe('path');
249+
expect(joinPath('path/')).toBe('path');
250250
});
251251

252252
test('should handle empty paths correctly', () => {
253-
expect(joinPath('')).toBe('');
253+
expect(joinPath('')).toBe('/');
254254
expect(joinPath('', '')).toBe('/');
255-
expect(joinPath('', 'path')).toBe('/path');
256-
expect(joinPath('path', '')).toBe('path/');
255+
expect(joinPath('', 'path')).toBe('path');
256+
expect(joinPath('path', '')).toBe('path');
257257
});
258258

259259
test('should handle paths with leading and trailing slashes correctly', () => {
260-
expect(joinPath('/path', 'to', 'file')).toBe('/path/to/file');
260+
expect(joinPath('/path', 'to', 'file')).toBe('path/to/file');
261261
expect(joinPath('path', 'to', '/file')).toBe('path/to/file');
262-
expect(joinPath('/path', 'to', '/file')).toBe('/path/to/file');
263-
expect(joinPath('/path/', '/to/', '/file/')).toBe('/path/to/file/');
262+
expect(joinPath('/path', 'to', '/file')).toBe('path/to/file');
263+
expect(joinPath('/path/', '/to/', '/file/')).toBe('path/to/file');
264+
});
265+
266+
test('should handle slashes only correctly', () => {
267+
expect(joinPath('/')).toBe('/');
268+
expect(joinPath('/', '/')).toBe('/');
269+
expect(joinPath('/', 'path')).toBe('path');
270+
expect(joinPath('path', '/')).toBe('path');
264271
});
265272
});
266273

0 commit comments

Comments
 (0)