Browse Source

Merge 0739319f83 into 23beb3a880

pull/529/merge
Dima Voytenko GitHub 9 years ago
parent
commit
641bb7041a
2 changed files with 29 additions and 1 deletions
  1. +11
    -1
      mustache.js
  2. +18
    -0
      test/sanitize-test.js

+ 11
- 1
mustache.js View File

@@ -552,8 +552,12 @@

Writer.prototype.unescapedValue = function unescapedValue (token, context) {
var value = context.lookup(token[1]);
if (value != null)
if (value != null) {
if (mustache.sanitizeUnescaped) {
return mustache.sanitizeUnescaped(value);
}
return value;
}
};

Writer.prototype.escapedValue = function escapedValue (token, context) {
@@ -621,6 +625,12 @@
// See https://github.com/janl/mustache.js/issues/244
mustache.escape = escapeHtml;

// Export the sanitizing function for unescaped values.
mustache.sanitizeUnescaped = null;
mustache.setUnescapedSanitizier = function setUnescapedSanitizier (sanitizeUnescaped) {
mustache.sanitizeUnescaped = sanitizeUnescaped;
};

// Export these mainly for testing, but also for advanced usage.
mustache.Scanner = Scanner;
mustache.Context = Context;


+ 18
- 0
test/sanitize-test.js View File

@@ -0,0 +1,18 @@
require('./helper');

var renderHelper = require('./render-helper');

var tests = renderHelper.getTests();

describe('Mustache.sanitizeUnescaped', function () {
beforeEach(function () {
Mustache.setUnescapedSanitizier(function(value) {
return value.toUpperCase();
});
});

it('requires template to be a string', function () {
assert.equal(Mustache.render('{{{value}}}', {value: '<b>abc</b>'}),
'<B>ABC</B>');
});
});

Loading…
Cancel
Save