Skip to content

Commit 9ecc0d1

Browse files
committed
enforce absolute path requirement on dataDirectory
1 parent 7904ee6 commit 9ecc0d1

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/extractors/BaseCSVExtractor.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class BaseCSVExtractor extends Extractor {
1616
this.url = url;
1717
this.csvModule = new CSVURLModule(this.url, this.unalterableColumns);
1818
} else if (fileName && dataDirectory) {
19+
if (!path.isAbsolute(dataDirectory)) throw new Error('dataDirectory is not an absolutePath, it needs to be.');
1920
this.filePath = path.join(dataDirectory, fileName);
2021
logger.debug(
2122
'Found fileName and dataDirectory arguments; creating a CSVFileModule with the provided dataDirectory and fileName',

test/extractors/BaseCSVExtractor.test.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,21 @@ describe('BaseCSVExtractor', () => {
1818
expect(fileNameDataDirectoryExtractor.csvModule).not.toBeUndefined();
1919
expect(fileNameDataDirectoryExtractor.csvModule.constructor.name).toEqual('CSVFileModule');
2020
});
21+
test('Should fail when the provided dataDirectory is not an absolute path', () => {
22+
expect(() => new BaseCSVExtractor({ fileName: 'example.csv', dataDirectory: './extractors/fixtures/' }))
23+
.toThrowError('dataDirectory is not an absolutePath, it needs to be.');
24+
});
2125
test('Should fail when provided only provided a fileName and no dataDirectory', () => {
22-
expect(() => new BaseCSVExtractor({ fileName: 'example.csv' })
23-
.toThrowError('Trying to instantiate a CSVExtractor without a valid filePath, url, or fileName+dataDirectory combination'));
26+
expect(() => new BaseCSVExtractor({ fileName: 'example.csv' }))
27+
.toThrowError('Trying to instantiate a CSVExtractor without a valid filePath, url, or fileName+dataDirectory combination');
2428
});
2529
test('Should fail when provided only provided a dataDirectory and no fileName', () => {
26-
expect(() => new BaseCSVExtractor({ dataDirectory: '/Users/dphelan/Development/mcode-extraction-framework/test/extractors/fixtures/' })
27-
.toThrowError('Trying to instantiate a CSVExtractor without a valid filePath, url, or fileName+dataDirectory combination'));
30+
expect(() => new BaseCSVExtractor({ dataDirectory: '/Users/dphelan/Development/mcode-extraction-framework/test/extractors/fixtures/' }))
31+
.toThrowError('Trying to instantiate a CSVExtractor without a valid filePath, url, or fileName+dataDirectory combination');
2832
});
2933
test('Should fail when provided none of the three options above', () => {
30-
expect(() => new BaseCSVExtractor({})
31-
.toThrowError('Trying to instantiate a CSVExtractor without a valid filePath, url, or fileName+dataDirectory combination'));
34+
expect(() => new BaseCSVExtractor({}))
35+
.toThrowError('Trying to instantiate a CSVExtractor without a valid filePath, url, or fileName+dataDirectory combination');
3236
});
3337
});
3438
});

0 commit comments

Comments
 (0)