Skip to content
Open
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
7 changes: 5 additions & 2 deletions ai2html.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 += '/';
}
Expand Down
4 changes: 4 additions & 0 deletions test/utils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down