Wrapped template descender in a recursion check. Fixed global leak in valid_block_type() check. Updated Readme to document if/when differences.
This commit is contained in:
parent
8d949ce6f0
commit
578150e389
17
README.md
17
README.md
|
@ -36,10 +36,13 @@ a string or a number.
|
||||||
### If
|
### If
|
||||||
|
|
||||||
An "if:<name>" section can contain other objects, but the entirety of
|
An "if:<name>" section can contain other objects, but the entirety of
|
||||||
the section is only rendered if the current context scope contains the
|
the section is only rendered if the current context scope, and *only*
|
||||||
current name, and the value associated with that name is "true" in a
|
the current context scope, contains the current name, and the value
|
||||||
boolean context. You might use to show someone's name, if the name
|
associated with that name is "true" in a boolean context. You might
|
||||||
field is populated, and show nothing if it isn't.
|
use to show someone's name, if the name field is populated, and show
|
||||||
|
nothing if it isn't. This is useful for detecting if the current
|
||||||
|
context has a field, but you don't want previous contexts' synonyms
|
||||||
|
showing up.
|
||||||
|
|
||||||
If your datasource returns:
|
If your datasource returns:
|
||||||
|
|
||||||
|
@ -49,6 +52,12 @@ Then your template would use:
|
||||||
|
|
||||||
{if:name}Hello {name}!{/if:name}
|
{if:name}Hello {name}!{/if:name}
|
||||||
|
|
||||||
|
### When
|
||||||
|
|
||||||
|
A "when:<name>" section is the same as the "if", but it will render if
|
||||||
|
the current context scope, and any previous context scope on the
|
||||||
|
stack, contains the current name.
|
||||||
|
|
||||||
### Block
|
### Block
|
||||||
|
|
||||||
A "block:<name>" section can contain other objects, but the entirety
|
A "block:<name>" section can contain other objects, but the entirety
|
||||||
|
|
|
@ -816,7 +816,7 @@ module.exports = (function() {
|
||||||
var _VBT_LENGTH = _VALID_BLOCK_TYPES.length;
|
var _VBT_LENGTH = _VALID_BLOCK_TYPES.length;
|
||||||
|
|
||||||
function is_valid_block_type(b) {
|
function is_valid_block_type(b) {
|
||||||
for(i = 0; i < _VBT_LENGTH; i++) {
|
for(var i = 0; i < _VBT_LENGTH; i++) {
|
||||||
if (_VALID_BLOCK_TYPES[i] == b) {
|
if (_VALID_BLOCK_TYPES[i] == b) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,8 +110,15 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
Contexter.prototype.render = function(name) {
|
Contexter.prototype.render = function(name) {
|
||||||
|
var ret;
|
||||||
if ((this.templates[name] != null) && _.isFunction(this.templates[name])) {
|
if ((this.templates[name] != null) && _.isFunction(this.templates[name])) {
|
||||||
return this.templates[name](this);
|
this.depth++;
|
||||||
|
if (this.depth > 10) {
|
||||||
|
throw new Error('recursion-error');
|
||||||
|
}
|
||||||
|
ret = this.templates[name](this);
|
||||||
|
this.depth--;
|
||||||
|
return ret;
|
||||||
} else {
|
} else {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
var _VBT_LENGTH = _VALID_BLOCK_TYPES.length;
|
var _VBT_LENGTH = _VALID_BLOCK_TYPES.length;
|
||||||
|
|
||||||
function is_valid_block_type(b) {
|
function is_valid_block_type(b) {
|
||||||
for(i = 0; i < _VBT_LENGTH; i++) {
|
for(var i = 0; i < _VBT_LENGTH; i++) {
|
||||||
if (_VALID_BLOCK_TYPES[i] == b) {
|
if (_VALID_BLOCK_TYPES[i] == b) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,14 @@ class Contexter
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
render: (name) ->
|
render: (name) ->
|
||||||
if @templates[name]? and _.isFunction(@templates[name]) then @templates[name](@) else ""
|
if @templates[name]? and _.isFunction(@templates[name])
|
||||||
|
@depth++
|
||||||
|
throw new Error('recursion-error') if @depth > 10
|
||||||
|
ret = @templates[name](@)
|
||||||
|
@depth--
|
||||||
|
ret
|
||||||
|
else
|
||||||
|
""
|
||||||
|
|
||||||
|
|
||||||
module.exports = (ast, data) ->
|
module.exports = (ast, data) ->
|
||||||
|
|
Loading…
Reference in New Issue