From 5e050a7d2327c396e5f8b36f4160d4bf4e492d7e Mon Sep 17 00:00:00 2001 From: Evgenus Date: Fri, 3 Oct 2014 09:42:42 +0300 Subject: [PATCH] Support using tokens multiple times closes #19 --- HISTORY.md | 5 +++++ index.js | 8 ++++---- test/shared/template.html | 1 + test/test.js | 12 ++++++++++++ 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 267778a..c94dde6 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,8 @@ +unreleased +========== + + * Support using tokens multiple times + 1.3.1 / 2014-10-01 ================== diff --git a/index.js b/index.js index ca6198f..da2749d 100644 --- a/index.js +++ b/index.js @@ -172,10 +172,10 @@ exports.html = function(req, res, files, next, dir, showUp, icons, path, view, t files.sort(fileSort); if (showUp) files.unshift({ name: '..' }); str = str - .replace('{style}', style.concat(iconStyle(files, icons))) - .replace('{files}', html(files, dir, icons, view)) - .replace('{directory}', dir) - .replace('{linked-path}', htmlPath(dir)); + .replace(/\{style\}/g, style.concat(iconStyle(files, icons))) + .replace(/\{files\}/g, html(files, dir, icons, view)) + .replace(/\{directory\}/g, dir) + .replace(/\{linked-path\}/g, htmlPath(dir)); var buf = new Buffer(str, 'utf8'); res.setHeader('Content-Type', 'text/html; charset=utf-8'); diff --git a/test/shared/template.html b/test/shared/template.html index 86ddf0c..04ed760 100644 --- a/test/shared/template.html +++ b/test/shared/template.html @@ -6,6 +6,7 @@

This is the test template

+

directory {directory}

{linked-path}

{files} diff --git a/test/test.js b/test/test.js index 70ea753..106ddbc 100644 --- a/test/test.js +++ b/test/test.js @@ -506,6 +506,18 @@ describe('serveIndex(root)', function () { .set('Accept', 'text/html') .expect(200, /ul#files/, done) }); + + it('should list directory twice', function (done) { + request(server) + .get('/users/') + .set('Accept', 'text/html') + .expect(function (res) { + var occurances = res.text.match(/directory \/users\//g) + if (occurances && occurances.length === 2) return + throw new Error('directory not listed twice') + }) + .expect(200, done) + }); }); describe('when setting a custom stylesheet', function () {