Skip to content

Commit

Permalink
[plugin installer] Look for forward or back slashes (#11332)
Browse files Browse the repository at this point in the history
* [plugin installer] Look for forward or back slashes when checking for directory

* [plugin installer] Test more file paths for directory check
  • Loading branch information
jbudz authored Apr 19, 2017
1 parent 6c2411d commit b6b6e8b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
18 changes: 17 additions & 1 deletion src/cli_plugin/install/__tests__/zip.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import rimraf from 'rimraf';
import path from 'path';
import os from 'os';
import glob from 'glob';
import { analyzeArchive, extractArchive } from '../zip';
import { analyzeArchive, extractArchive, _isDirectory } from '../zip';

describe('kibana cli', function () {

Expand Down Expand Up @@ -64,4 +64,20 @@ describe('kibana cli', function () {
});
});

describe('_isDirectory', () => {
it('should check for a forward slash', () => {
expect(_isDirectory('/foo/bar/')).to.be(true);
});

it('should check for a backslash', () => {
expect(_isDirectory('\\foo\\bar\\')).to.be(true);
});

it('should return false for files', () => {
expect(_isDirectory('foo.txt')).to.be(false);
expect(_isDirectory('\\path\\to\\foo.txt')).to.be(false);
expect(_isDirectory('/path/to/foo.txt')).to.be(false);
});
});

});
8 changes: 6 additions & 2 deletions src/cli_plugin/install/zip.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ export function analyzeArchive(archive) {
});
}

const isDirectoryRegex = /(\/|\\)$/;
export function _isDirectory(filename) {
return isDirectoryRegex.test(filename);
}

export function extractArchive(archive, targetDir, extractPath) {
return new Promise((resolve, reject) => {
yauzl.open(archive, { lazyEntries: true }, function (err, zipfile) {
Expand All @@ -87,8 +92,7 @@ export function extractArchive(archive, targetDir, extractPath) {
fileName = path.join(targetDir, fileName);
}

if (/\/$/.test(fileName)) {
// directory file names end with '/'
if (_isDirectory(fileName)) {
mkdirp(fileName, function (err) {
if (err) {
return reject(err);
Expand Down

0 comments on commit b6b6e8b

Please sign in to comment.