Skip to content

Commit

Permalink
fix: ban emitFile via absolute paths on Windows OS
Browse files Browse the repository at this point in the history
  • Loading branch information
SASUKE40 committed Apr 22, 2020
1 parent 925d302 commit 59dbcbd
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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'
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
throw new Error('should not build');

0 comments on commit 59dbcbd

Please sign in to comment.