({ buildDirectory, fileCache })
| 21 | const validPathPattern = /^[A-Za-z0-9\-_/.:]+$/; |
| 22 | |
| 23 | function createReadConfigFile({ buildDirectory, fileCache }) { |
| 24 | async function readConfigFile(filePath) { |
| 25 | if (!validPathPattern.test(filePath) || filePath.includes('..')) { |
| 26 | return null; |
| 27 | } |
| 28 | const fileContent = await readFile(path.resolve(buildDirectory, filePath)); |
| 29 | if (getFileExtension(filePath) === 'json') { |
| 30 | return serializer.deserializeFromString(fileContent); |
| 31 | } |
| 32 | return fileContent; |
| 33 | } |
| 34 | return cachedPromises({ |
| 35 | cache: fileCache, |
| 36 | getter: readConfigFile, |
| 37 | }); |
| 38 | } |
| 39 | |
| 40 | export default createReadConfigFile; |
no test coverage detected