mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[plugin cli] Fix file:/// paths on Windows
This commit is contained in:
parent
2796e7798b
commit
f47bc1e802
2 changed files with 27 additions and 2 deletions
|
@ -6,7 +6,7 @@ import rimraf from 'rimraf';
|
|||
import mkdirp from 'mkdirp';
|
||||
import Logger from '../../lib/logger';
|
||||
import { UnsupportedProtocolError } from '../../lib/errors';
|
||||
import { download, _downloadSingle } from '../download';
|
||||
import { download, _downloadSingle, _getFilePath } from '../download';
|
||||
import { join } from 'path';
|
||||
|
||||
describe('kibana cli', function () {
|
||||
|
@ -133,6 +133,22 @@ describe('kibana cli', function () {
|
|||
|
||||
});
|
||||
|
||||
describe('_getFilePath', function () {
|
||||
it('should decode paths', function () {
|
||||
expect(_getFilePath('Test%20folder/file.zip')).to.equal('Test folder/file.zip');
|
||||
});
|
||||
|
||||
it('should remove the leading slash from windows paths', function () {
|
||||
const platform = Object.getOwnPropertyDescriptor(process, 'platform');
|
||||
Object.defineProperty(process, 'platform', { value: 'win32' });
|
||||
|
||||
expect(_getFilePath('/C:/foo/bar')).to.equal('C:/foo/bar');
|
||||
|
||||
Object.defineProperty(process, 'platform', platform);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('download', function () {
|
||||
it('should loop through bad urls until it finds a good one.', function () {
|
||||
const filePath = join(__dirname, 'replies/test_plugin.zip');
|
||||
|
|
|
@ -3,12 +3,21 @@ import downloadLocalFile from './downloaders/file';
|
|||
import { UnsupportedProtocolError } from '../lib/errors';
|
||||
import { parse } from 'url';
|
||||
|
||||
export function _getFilePath(filePath) {
|
||||
const decodedPath = decodeURI(filePath);
|
||||
const isWindows = /^win/.test(process.platform);
|
||||
if (isWindows) {
|
||||
return decodedPath.replace(/^\//, '');
|
||||
}
|
||||
return decodedPath;
|
||||
}
|
||||
|
||||
export function _downloadSingle(settings, logger, sourceUrl) {
|
||||
const urlInfo = parse(sourceUrl);
|
||||
let downloadPromise;
|
||||
|
||||
if (/^file/.test(urlInfo.protocol)) {
|
||||
downloadPromise = downloadLocalFile(logger, decodeURI(urlInfo.path), settings.tempArchiveFile);
|
||||
downloadPromise = downloadLocalFile(logger, _getFilePath(urlInfo.path), settings.tempArchiveFile);
|
||||
} else if (/^https?/.test(urlInfo.protocol)) {
|
||||
downloadPromise = downloadHttpFile(logger, sourceUrl, settings.tempArchiveFile, settings.timeout);
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue