From 50cdd6c1b8618fbeeb7c8507ca04567793e70bab Mon Sep 17 00:00:00 2001 From: Max Kohler Date: Sun, 27 Jul 2025 12:27:03 +0200 Subject: [PATCH 1/2] Don't slice leading slash off the first argument --- ai2html.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ai2html.js b/ai2html.js index 4ef9225..211ac6a 100644 --- a/ai2html.js +++ b/ai2html.js @@ -999,10 +999,13 @@ function applyTemplate(template, replacements) { // Similar to Node.js path.join() function pathJoin() { var path = ''; - forEach(arguments, function(arg) { + forEach(arguments, function(arg, i) { if (!arg) return; arg = String(arg); - arg = arg.replace(/^\/+/, '').replace(/\/+$/, ''); + if (i > 0){ + arg = arg.replace(/^\/+/, ''); // leading + } + arg = arg.replace(/\/+$/, ''); // trailing if (path.length > 0) { path += '/'; } From e3506d46e23bce7ada0ca0ce4fd7044c6fa20c76 Mon Sep 17 00:00:00 2001 From: Max Kohler Date: Mon, 28 Jul 2025 10:03:30 +0200 Subject: [PATCH 2/2] Add test --- test/utils-test.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/utils-test.js b/test/utils-test.js index fc257c0..f6382e5 100644 --- a/test/utils-test.js +++ b/test/utils-test.js @@ -175,6 +175,10 @@ describe('Utility function tests', function() { it('removes duplicate slashes', function() { assert.equal(lib.pathJoin('ai/', '/output/', 'image.svg'), 'ai/output/image.svg'); }) + + it('retains leading slash in first argument', function() { + assert.equal(lib.pathJoin('/c/', '/output/', 'image.svg'), '/c/output/image.svg'); + }) }) describe('pathSplit()', function() {