sanitize filenames before SSRing - fixes #1005

pull/1009/head
Rich Harris 7 years ago committed by GitHub
parent 8efd1a923e
commit 774caf42ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -26,10 +26,14 @@ function _deregister(extension) {
function _register(extension) { function _register(extension) {
require.extensions[extension] = function(module, filename) { require.extensions[extension] = function(module, filename) {
const name = path.basename(filename)
.slice(0, -path.extname(filename).length)
.replace(/^\d/, '_$&')
.replace(/[^a-zA-Z0-9_$]/g, '');
const options = Object.assign({}, compileOptions, { const options = Object.assign({}, compileOptions, {
filename, filename,
name: capitalise(path.basename(filename) name: capitalise(name),
.replace(new RegExp(`${extension.replace('.', '\\.')}$`), '')),
generate: 'ssr' generate: 'ssr'
}); });

@ -175,11 +175,17 @@ function capitalise(str) {
export function showOutput(cwd, options = {}, s = svelte) { export function showOutput(cwd, options = {}, s = svelte) {
glob.sync('**/*.html', { cwd }).forEach(file => { glob.sync('**/*.html', { cwd }).forEach(file => {
if (file[0] === '_') return; if (file[0] === '_') return;
const name = path.basename(file)
.slice(0, -path.extname(file).length)
.replace(/^\d/, '_$&')
.replace(/[^a-zA-Z0-9_$]/g, '');
const { code } = s.compile( const { code } = s.compile(
fs.readFileSync(`${cwd}/${file}`, 'utf-8'), fs.readFileSync(`${cwd}/${file}`, 'utf-8'),
Object.assign(options, { Object.assign(options, {
filename: file, filename: file,
name: capitalise(path.basename(file).replace(/\.html$/, '')) name: capitalise(name)
}) })
); );

@ -0,0 +1,9 @@
<Foo/>
<script>
import Foo from './@foo.html';
export default {
components: { Foo }
};
</script>
Loading…
Cancel
Save