Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
131 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,4 @@ rules: | |
no-return-assign: 2 | ||
no-use-before-define: [ 2, nofunc ] | ||
no-path-concat: 2 | ||
no-useless-escape: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,3 +32,4 @@ node_modules | |
|
||
# Minified bundle | ||
doT.min.js | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
language: node_js | ||
node_js: | ||
- "0.10" | ||
- "0.12" | ||
- "4" | ||
- "6" | ||
- "7" | ||
- "8" | ||
- "10" | ||
- "12" | ||
- "13" | ||
after_script: | ||
- coveralls < coverage/lcov.info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
'use strict'; | ||
|
||
var assert = require('assert'); | ||
var doT = require('..'); | ||
var fs = require('fs'); | ||
|
||
|
||
describe('doT.process', function() { | ||
beforeEach(function() { | ||
removeCompiledTemplateFiles(); | ||
}); | ||
|
||
afterEach(function() { | ||
removeCompiledTemplateFiles(); | ||
}); | ||
|
||
function removeCompiledTemplateFiles() { | ||
try { fs.unlinkSync('./test/templates/test.js'); } catch(e) {} | ||
} | ||
|
||
it('should compile all templates in folder', function() { | ||
const templates = doT.process({path: './test/templates'}); | ||
var str = templates.test({data: 2}); | ||
assert.equal(str, '21'); | ||
|
||
var js = fs.statSync('./test/templates/test.js'); | ||
assert.ok(js.isFile()); | ||
|
||
// code below passes if the test is run without coverage using `npm run test-spec` | ||
// because source code of doT.encodeHTMLSource is used inside compiled templates | ||
|
||
// var fn = require('./templates/test.js'); | ||
// var str = fn({data: 2}); | ||
// assert.equal(str, '21'); | ||
}); | ||
|
||
|
||
it('should ignore varname with polluted object prototype', function() { | ||
var currentLog = console.log; | ||
console.log = log; | ||
var logged; | ||
|
||
Object.prototype.templateSettings = {varname: 'it=(console.log("executed"),{})'}; | ||
|
||
try { | ||
const templates = doT.process({path: './test/templates'}); | ||
assert.notEqual(logged, 'executed'); | ||
// injected code can only be executed if undefined is passed to template function | ||
templates.test(); | ||
assert.notEqual(logged, 'executed'); | ||
} finally { | ||
console.log = currentLog; | ||
} | ||
|
||
function log(str) { | ||
logged = str; | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{{=it && it.data}} | ||
{{#def.test}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{{=it && it.data}} | ||
{{#def.test}} |