Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handlebars Partials #82

Open
mdelbuono opened this issue Aug 2, 2020 · 1 comment
Open

Handlebars Partials #82

mdelbuono opened this issue Aug 2, 2020 · 1 comment

Comments

@mdelbuono
Copy link

In index.js, line 92 loads the default partials as follows:

 registerPartials(path.resolve(__dirname, './partials/**/*.hbs'))  

The glob path gests unfolded usign FileSet which in turns uses glob.
The problem is that, if __dirname contains special glob characters (e.g. [ ] like in my case), FileSet will fail listing all the .hbs files and no partial will be registered.

Bottomline is: __dirname should be escaped.

@mdelbuono
Copy link
Author

I fixed it as follows:

registerPartials(path.resolve(escapeGlob(__dirname), './partials/**/*.hbs'))

Where the escapeGlob function is defined below:

function escapeGlob (glob) {
  return glob
    .replace(/\\/g, '\\\\')
    .replace(/\*/g, '\\*')
    .replace(/\?/g, '\\?')
    .replace(/\[/g, '\\[')
    .replace(/\]/g, '\\]')
    .replace(/\{/g, '\\{')
    .replace(/\}/g, '\\}')
    .replace(/\)/g, '\\)')
    .replace(/\(/g, '\\(')
    .replace(/\!/g, '\\!');
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant