From 33be4eff67d30c312f79bb257d89c6bd9846de2a Mon Sep 17 00:00:00 2001 From: Eric Caron Date: Wed, 5 Mar 2014 14:08:25 -0600 Subject: [PATCH] Introducing the escape character, as discussed in #427 --- lib/filters.js | 5 ++++- tests/filters.test.js | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/filters.js b/lib/filters.js index 7637fb8d..ed13ae03 100644 --- a/lib/filters.js +++ b/lib/filters.js @@ -92,7 +92,10 @@ exports.date = function (input, format, offset, abbr) { for (i; i < l; i += 1) { cur = format.charAt(i); - if (dateFormatter.hasOwnProperty(cur)) { + if (cur === '\\') { + i += 1; + out += (i < l) ? format.charAt(i) : cur; + } else if (dateFormatter.hasOwnProperty(cur)) { out += dateFormatter[cur](date, offset, abbr); } else { out += cur; diff --git a/tests/filters.test.js b/tests/filters.test.js index 880d8993..a253364c 100644 --- a/tests/filters.test.js +++ b/tests/filters.test.js @@ -103,7 +103,12 @@ var n = new Swig(), { c: 'v|date("S")', v: makeDate(420, 2011, 8, 13), e: 'th' }, { c: 'v|date("S")', v: makeDate(420, 2011, 8, 21), e: 'st' }, { c: 'v|date("S")', v: makeDate(420, 2011, 8, 22), e: 'nd' }, - { c: 'v|date("S")', v: makeDate(420, 2011, 8, 23), e: 'rd' } + { c: 'v|date("S")', v: makeDate(420, 2011, 8, 23), e: 'rd' }, + + // Week + { c: 'v|date("\\D")', v: d, e: 'D' }, + { c: 'v|date("\\t\\e\\s\\t")', v: d, e: 'test' }, + { c: 'v|date("\\\\D")', v: d, e: '\\Tue' } ], 'default': [ { c: 'v|default("tacos")', v: 'foo', e: 'foo' },