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

fix: replace backslash in partials with forward slash #553

Merged
merged 1 commit into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/express-handlebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,8 @@ export default class ExpressHandlebars {
if (options._throwTestError) {
throw new Error("test");
}
return (await dir).concat();

return (await dir).map(d => d.replace(/\\/g, "/"));
} catch (err) {
delete cache[dirPath];
throw err;
Expand Down
14 changes: 13 additions & 1 deletion spec/express-handlebars.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ describe("express-handlebars", () => {
expect(partials).toEqual({
partial: expect.any(Function),
"partial-latin1": expect.any(Function),
"subdir/partial-subdir": expect.any(Function),
});
});

Expand All @@ -67,6 +68,7 @@ describe("express-handlebars", () => {
expect(partials).toEqual({
partial: expect.any(Function),
"partial-latin1": expect.any(Function),
"subdir/partial-subdir": expect.any(Function),
});
});

Expand Down Expand Up @@ -109,6 +111,7 @@ describe("express-handlebars", () => {
expect(partials).toEqual({
partial: expect.any(Function),
"partial-latin1": expect.any(Function),
"subdir/partial-subdir": expect.any(Function),
});
});

Expand Down Expand Up @@ -241,7 +244,7 @@ describe("express-handlebars", () => {
const exphbs = expressHandlebars.create();
const dirPath = fixturePath("templates");
const templates = await exphbs.getTemplates(dirPath);
const paths = Object.keys(templates).map(t => t.replace(/\\/g, "/"));
const paths = Object.keys(templates);
expect(paths).toEqual([
"template.handlebars",
"template-latin1.handlebars",
Expand Down Expand Up @@ -322,6 +325,15 @@ describe("express-handlebars", () => {
expect(html.replace(/\r/g, "")).toBe("<h1>partial test text</h1>\n<p>test text</p>");
});

test("should render with subdir/partial", async () => {
const exphbs = expressHandlebars.create({
partialsDir: fixturePath("partials"),
});
const filePath = fixturePath("render-subdir-partial.handlebars");
const html = await exphbs.render(filePath, { text: "test text" });
expect(html.replace(/\r/g, "")).toBe("<h1>subdir partial test text</h1>\n<p>test text</p>");
});

test("should render with runtimeOptions", async () => {
const exphbs = expressHandlebars.create({
runtimeOptions: { allowProtoPropertiesByDefault: true },
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/partials/subdir/partial-subdir.handlebars
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
subdir partial {{text}}
2 changes: 2 additions & 0 deletions spec/fixtures/render-subdir-partial.handlebars
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>{{> subdir/partial-subdir}}</h1>
<p>{{text}}</p>