Skip to content

Commit

Permalink
fix: replace backslash in partials with forward slash (#553)
Browse files Browse the repository at this point in the history
  • Loading branch information
UziTech authored Apr 12, 2023
1 parent 51f168d commit 2ecd784
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
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>

0 comments on commit 2ecd784

Please sign in to comment.