From 7d969a05de6a45543bc31a3b982828865bc57cdb Mon Sep 17 00:00:00 2001 From: Jean Lauliac Date: Thu, 23 Nov 2017 03:10:04 -0800 Subject: [PATCH] packager-worker-for-buck: bundleCommand-test.js: add more consistency Reviewed By: davidaurelio Differential Revision: D6395673 fbshipit-source-id: 24516bd456a231708891e789f1d5aa5c18f4eeca --- local-cli/__mocks__/fs.js | 3 +++ local-cli/__tests__/fs-mock-test.js | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/local-cli/__mocks__/fs.js b/local-cli/__mocks__/fs.js index db689247e3dd39..9e5f6116d1de5b 100644 --- a/local-cli/__mocks__/fs.js +++ b/local-cli/__mocks__/fs.js @@ -67,6 +67,7 @@ fs.readdir.mockImplementation((filepath, callback) => { }); fs.readFile.mockImplementation(function(filepath, encoding, callback) { + filepath = path.normalize(filepath); callback = asyncCallback(callback); if (arguments.length === 2) { callback = encoding; @@ -90,6 +91,7 @@ fs.readFile.mockImplementation(function(filepath, encoding, callback) { }); fs.readFileSync.mockImplementation(function(filepath, encoding) { + filepath = path.normalize(filepath); const node = getToNode(filepath); if (isDirNode(node)) { throw new Error('Error readFileSync a dir: ' + filepath); @@ -103,6 +105,7 @@ fs.readFileSync.mockImplementation(function(filepath, encoding) { fs.writeFile.mockImplementation(asyncify(fs.writeFileSync)); fs.writeFileSync.mockImplementation((filePath, content, options) => { + filePath = path.normalize(filePath); if (options == null || typeof options === 'string') { options = {encoding: options}; } diff --git a/local-cli/__tests__/fs-mock-test.js b/local-cli/__tests__/fs-mock-test.js index 43efc8bcec70ca..7e9bf07f7b4431 100644 --- a/local-cli/__tests__/fs-mock-test.js +++ b/local-cli/__tests__/fs-mock-test.js @@ -46,6 +46,12 @@ describe('fs mock', () => { fs.writeFileSync('/dir/test', 'foobar', 'utf8'), ).toThrowError('ENOENT: no such file or directory'); }); + + it('properly normalizes paths', () => { + fs.writeFileSync('/test/foo/../bar/../../tadam', 'beep', 'utf8'); + const content = fs.readFileSync('/glo/../tadam', 'utf8'); + expect(content).toEqual('beep'); + }); }); describe('mkdirSync()', () => {