Skip to content

Commit

Permalink
fix: ban emitFile via absolute paths on Windows OS (#3509)
Browse files Browse the repository at this point in the history
Co-authored-by: Lukas Taegert-Atkinson <lukastaegert@users.noreply.github.com>
  • Loading branch information
SASUKE40 and lukastaegert committed Apr 22, 2020
1 parent 0d352bf commit bd2973a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/utils/relativeId.ts
Expand Up @@ -16,6 +16,7 @@ export function isPlainPathFragment(name: string) {
return (
name[0] !== '/' &&
!(name[0] === '.' && (name[1] === '/' || name[1] === '.')) &&
sanitizeFileName(name) === name
sanitizeFileName(name) === name &&
!isAbsolute(name)
);
}
19 changes: 19 additions & 0 deletions test/function/samples/emit-file/invalid-asset-name3/_config.js
@@ -0,0 +1,19 @@
module.exports = {
description: 'throws for invalid asset names with absolute path on Windows OS',
options: {
plugins: {
name: 'test-plugin',
buildStart() {
this.emitFile({ type: 'asset', name: 'F:\\test.ext', source: 'content' });
}
}
},
error: {
code: 'PLUGIN_ERROR',
hook: 'buildStart',
message:
'The "fileName" or "name" properties of emitted files must be strings that are neither absolute nor relative paths and do not contain invalid characters, received "F:\\test.ext".',
plugin: 'test-plugin',
pluginCode: 'VALIDATION_ERROR'
}
};
@@ -0,0 +1 @@
throw new Error('should not build');

0 comments on commit bd2973a

Please sign in to comment.