mirror of
https://github.com/laurent22/joplin.git
synced 2025-02-13 19:42:36 +02:00
Plugins: Fix crash when path includes trailing slash
This commit is contained in:
parent
8305eb4403
commit
918b768634
@ -44,6 +44,8 @@ describe('services_PluginService', function() {
|
||||
const service = newPluginService();
|
||||
await service.loadAndRunPlugins([`${testPluginDir}/simple`]);
|
||||
|
||||
expect(() => service.pluginById('simple')).not.toThrowError();
|
||||
|
||||
const allFolders = await Folder.all();
|
||||
expect(allFolders.length).toBe(1);
|
||||
expect(allFolders[0].title).toBe('my plugin folder');
|
||||
@ -54,6 +56,12 @@ describe('services_PluginService', function() {
|
||||
expect(allNotes[0].parent_id).toBe(allFolders[0].id);
|
||||
}));
|
||||
|
||||
it('should load and run a simple plugin and handle trailing slash', asyncTest(async () => {
|
||||
const service = newPluginService();
|
||||
await service.loadAndRunPlugins([`${testPluginDir}/simple/`]);
|
||||
expect(() => service.pluginById('simple')).not.toThrowError();
|
||||
}));
|
||||
|
||||
it('should load and run a plugin that uses external packages', asyncTest(async () => {
|
||||
const service = newPluginService();
|
||||
await service.loadAndRunPlugins([`${testPluginDir}/withExternalModules`]);
|
||||
|
@ -4,6 +4,7 @@ import Global from './api/Global';
|
||||
import BasePluginRunner from './BasePluginRunner';
|
||||
import BaseService from '../BaseService';
|
||||
import shim from '../../shim';
|
||||
import { rtrimSlashes } from '../../path-utils';
|
||||
const { filename, dirname } = require('../../path-utils');
|
||||
const uslug = require('uslug');
|
||||
|
||||
@ -86,11 +87,15 @@ export default class PluginService extends BaseService {
|
||||
}
|
||||
|
||||
public async loadPluginFromString(pluginId: string, baseDir: string, jsBundleString: string): Promise<Plugin> {
|
||||
baseDir = rtrimSlashes(baseDir);
|
||||
|
||||
const r = await this.parsePluginJsBundle(jsBundleString);
|
||||
return this.loadPlugin(pluginId, baseDir, r.manifestText, r.scriptText);
|
||||
}
|
||||
|
||||
private async loadPluginFromPath(path: string): Promise<Plugin> {
|
||||
path = rtrimSlashes(path);
|
||||
|
||||
const fsDriver = shim.fsDriver();
|
||||
|
||||
if (path.toLowerCase().endsWith('.js')) return this.loadPluginFromString(filename(path), dirname(path), await fsDriver.readFile(path));
|
||||
@ -110,6 +115,8 @@ export default class PluginService extends BaseService {
|
||||
}
|
||||
|
||||
private async loadPlugin(pluginId: string, baseDir: string, manifestText: string, scriptText: string): Promise<Plugin> {
|
||||
baseDir = rtrimSlashes(baseDir);
|
||||
|
||||
const manifest = manifestFromObject(JSON.parse(manifestText));
|
||||
|
||||
// After transforming the plugin path to an ID, multiple plugins might end up with the same ID. For
|
||||
|
Loading…
x
Reference in New Issue
Block a user